|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Breadth First Traversal
Hi Dan,
> 1) Can Breadth First Traversal be coded without <xsl:call-template>?
> In other words, just use <xsl:apply-templates select="?">.
If you're still interested, what about:
<xsl:variable name="as" select="//a" />
<xsl:template match="a">
<!-- give the output for the a element -->
<xsl:value-of select="@id" />
<xsl:text>
</xsl:text>
<!-- work out the depth of this a element -->
<xsl:variable name="depth" select="count(ancestor::a)" />
<!-- find the next node in the document at the same depth -->
<xsl:variable name="next"
select="following::a[count(ancestor::a) = $depth][1]" />
<xsl:choose>
<!-- if there is one, apply templates to it -->
<xsl:when test="$next">
<xsl:apply-templates select="$next" />
</xsl:when>
<!-- if there isn't, apply templates to the first node in the
document that has a depth one greater than this one -->
<xsl:otherwise>
<xsl:apply-templates
select="$as[count(ancestor::a) = $depth + 1][1]" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
(Actually, you can *always* avoid using xsl:call-template by using a
moded template instead, but I think you were just after a different
technique here.)
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








