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

Re: sorting into a tree structure

Subject: Re: sorting into a tree structure
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 06 Oct 2009 18:53:07 +0200
Re:  sorting into a tree structure
jim mcgovern wrote:

I'd like to limit the number of levels that the tree goes down.
What's the best way of achieving this?  Is this through
count(ancestor::*)?

Your input is a flat list so using the ancestor axis on the input does not help.
Are you thinking about using the ancestor axis on the output tree? With XSLT 1.0 you can't use XPath on result tree or temorary trees without using an extension function like exsl:node-set.


But you could pass a level down your template e.g.

    <xsl:template match="folders">
        <ul>
          <xsl:apply-templates select="key('val', '')">
            <xsl:with-param name="level" select="1"/>
          </xsl:apply-templates>
        </ul>
    </xsl:template>

    <xsl:template match="Item">
        <xsl:param name="level"/>
        <xsl:choose>
            <xsl:when test="key('val', @ID) and $level &lt;= $max-level">
                <li><xsl:value-of select="@title"/></li>
                <ul>
                  <xsl:apply-templates select="key('val', @ID)">
                    <xsl:sort select="@order" data-type="number"/>
                    <xsl:with-param name="level" select="$level + 1"/>
                  </xsl:apply-templates>
                </ul>
            </xsl:when>
            <xsl:otherwise>
                <li><xsl:value-of select="@title"/></li>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

<xsl:param name="max-level" select="10"/>

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

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.