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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl for-each

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
US
hi,

I am manipulating some xml from an asp file using some xsl transformation. I was using the same estructure other times but in this case there's something wrong with the 'for-each' loop because I retrieve nothing.

This is the xml data:

<return>
<row>
<NativeName>English, United States</NativeName>
<Enum>1</Enum>
</row>
<row>
<NativeName>Deutsch, German, Germany</NativeName>
<Enum>3</Enum>
</row>
</return>

if I apply the following:

<xsl:stylesheet xmlns:xsl=' version='1.0'>
<xsl:template match='/return'>
<xsl:value-of select='row/NativeName' />
</xsl:template>
</xsl:stylesheet>

it obviously only returns one result, so i need a loop, but if i use:

<xsl:stylesheet xmlns:xsl=' version='1.0'>
<xsl:template match='/return'>
<xsl:for-each select='row'>
<xsl:value-of select='row/NativeName' />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

it doesn't return all values....somebody sees whats wrong?
thanxs!
alej
 
Using <xsl:for-each> you try to find a row-node within each row node.
It should be:
<xsl:for-each select='row'>
<xsl:value-of select='NativeName' />

Apart from <xsl:for-each> you could also use:
Code:
<xsl:stylesheet xmlns:xsl='[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform'[/URL]   version='1.0'>

<xsl:template match='/return'>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="row">
<xsl:value-of select='NativeName' />
</xsl:template>
</xsl:stylesheet>

Good luck
 
thanxs you are right...i discovered it this morning :p

cheers,
alej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top