|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: building hierarchy from path 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








