[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Breadth First Traversal

Subject: Re: Breadth First Traversal
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 8 May 2001 15:11:29 +0100
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>&#xA;</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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.