This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Breadth First Traversal
- To: Dan Diebolt <dandiebolt at yahoo dot com>
- Subject: Re: [xsl] Breadth First Traversal
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Tue, 8 May 2001 15:11:29 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20010503024055.54843.qmail@web12605.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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