oo***********@yahoo.com.au (oooooo0000000) wrote in message news:<41**************************@posting.google. com>...
I have an XML file of varying nesting depth...
<catalouge>
<item id="1">
<name/>
<item id="23">
<name/>
<item id="55">
<name/>
</item>
</item>
<item id="7">
<name/>
</item>
</catalouge>
So, each item can contain many items.
I'm trying to get my XSLT to recursivly loop through each item to
print it out in block quotes eg
1 name
23 name
55 name
7 name
How can I get a <xsl:for-each> loop to go through the whole tree?
Easy; don't. Use apply-templates. If you make this a general habit you
will write much more efficient code. I think this does it in 1.0:
(A quick hack, and untested; there is probably a more efficient way
even if it works, but you get the idea.)
<xsl:template match="item">
<xsl:apply-templates select="*">
</xsl:template>
<!-- if you're doing what I think you're doing (?) -->
<xsl:template match="item/*[not(self::item)]">
<!--
one of the few occasions I'll use for-each,
and even then I'd be more inclined to use a 'repeat'
subtemplate with count(ancestor::item) supplied as a parameter
-->
<xsl:for-each select="ancestor::item">
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:value-of select="concat(parent::item/@id, ' ', name())"/>
<xsl:text>
</xsl:text><!-- output an EOL character - I hate breaking indent
style to do that, so I usually use a global
text variable called $EOL or similar -->
</xsl:template>
--
Robin Johnson
Lead Developer, enCircle Solutions Ltd.
first initial last name at encircle dot co dot uk