[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: building hierarchy from path string
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
|
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
|