Re: [xsl] building hierarchy from path string

Subject: Re: [xsl] building hierarchy from path string
From: "John-Mason P. Shackelford" <john-mason@xxxxxxxxxxxxxxx>
Date: Wed, 05 Dec 2001 16:31:08 -0600
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