[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: "John-Mason P. Shackelford" <john-mason@xxxxxxxxxxxxxxx>
Date: Wed, 05 Dec 2001 16:31:08 -0600
mason string
Jeni,

Wow, Jeni, thanks!

They say that the best programmers are at least ten times more productive than average. I believe it.

I made a slight modification to the stylesheet so that the numbers of characters per tier in the path can change. Unfortunately the it doesn't work. :p I get complaints about the use of the variable $tierChars, but it looks legal to me. Any idea as to what I am doing wrong?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text/xml" indent="yes" />
<xsl:variable name="tierChars">
<xsl:value-of select="/tree/descriptor/@chars-per-tier" />
</xsl:variable>
<xsl:key name="children" match="node" use="substring(@path, 1, @depth * $tierChars)" />
<xsl:template match="tree/node-list">
<tree>
<xsl:apply-templates select="key('children','')" />
</tree>
</xsl:template>
<xsl:template match="node">
<node name="{@name}">
<xsl:apply-templates select="key('children', substring(@path,1,(@depth + 1) * $tierChars))">
<xsl:sort select="@path" />
</xsl:apply-templates>
</node>
</xsl:template>
</xsl:stylesheet>


My XML input is as follows:

<tree>
  <descriptor chars-per-tier="2" depth="3" />
  <node-list>
      <node depth="0" OID="1" name="Animals" path="100000" />
      <node depth="1" OID="2" name="Reptile" path="102000" />
      <node depth="2" OID="5" name="Snake" path="102010" />
      <node depth="2" OID="6" name="Crock" path="102020" />
      <node depth="2" OID="7" name="Gator" path="102030" />
      <node depth="1" OID="3" name="Bird" path="103000" />
      <node depth="1" OID="4" name="Mamal" path="103000" />
  </node-list>
</tree>

Thanks again,

John-Mason
--
http://john-mason.shackelford.org


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.