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

Re: building hierarchy from path string

Subject: Re: building hierarchy from path string
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 6 Dec 2001 00:29:47 +0000
shacke
Hi John-Mason,

>     <xsl:key name="children" match="node" use="substring(@path, 1,
> @depth * $tierChars)" />

Unfortunately you can't use variables in keys :(  [It's supposed to
avoid circular definitions - variables defined using keys using
variables - but actually it's just a pain in the neck.]

But since that value's coming from the source document, you can do:

<xsl:key name="children" match="node"
         use="substring(@path, 1, @depth *
                                  /tree/descriptor/@chars-per-tier)" />

And you can use the variable later on in the document as you are
doing.

If you were passing it in as a parameter it would be more difficult -
the way out would be to substitute the uses of the key for the full
horror of the paths:

<xsl:template match="tree">
  <tree>
    <xsl:apply-templates
      select="node[not(substring(@path, 1, @depth * $tierChars))]" />
  </tree>
</xsl:template>

<xsl:template match="node">
  <node name="{@name}">
    <xsl:apply-templates
      select="../node[substring(@path, 1, @depth * $tierChars) =
                      substring(current()/@path, 1,
                                (@depth + 1) * $tierChars))">
      <xsl:sort select="@path" />
    </xsl:apply-templates>
  </node>
</xsl:template>

But this is a lot less efficient than using the key and should be
avoided if possible.

Cheers,

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.