Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

breaking out of an xsl:for-each statement after the first one

Status
Not open for further replies.

wrbodine

Programmer
Aug 24, 2000
302
US
Hi,

In an XSL page, how would I go about getting only for the first set of values, when using <xsl:for-each> tags? Maybe I need to use another tag besides xsl:for-each?

like, in the following code:
<xsl:element name=&quot;input&quot;>
<xsl:attribute name=&quot;type&quot;>text</xsl:attribute>
<xsl:attribute name=&quot;name&quot;>SearchValue</xsl:attribute>
<xsl:for-each select=&quot;../SearchParams/Search&quot;>
<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;@SearchValue&quot;/></xsl:attribute>
</xsl:for-each>
</xsl:element>

I only want to get the first value that's in @SearchValue, which would be 'Smith', in the first <Search> tag from XML like the following:
<SearchParams>
<Search SearchValue = 'Smith' SearchField = 'LastName' />
<Search SearchValue = 'Mike' SearchField = 'FirstName' />
</SearchParams>

Thanks,
Ray
 
Why do you want to use for-each for-that? :)


why not go directly for the value with value-of select?
Code:
<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;../SearchParams/Search@SearchValue&quot;/></xsl:attribute>

[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
Thanks Nosferatu!

That works great, exactly what I needed.... For anyone else checking it out, it needs a / before the attribute:

<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;../SearchParams/Search/@SearchValue&quot;/></xsl:attribute>

I'm still getting double values at some point, but am able to take care of this elsewhere in code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top