Subject: Re: [xsl] using parameters to identify element levels From: David Carlisle <davidc@xxxxxxxxx> Date: Mon, 4 Dec 2006 16:22:41 GMT |
> So it appears that the re-setting of the parameter values isn't > working ... suggestions? parameter values are set with xsl;with-param which you haven't used at all. I'd do something like the following. <x> <item ItemID="1" ParentID="0">item1</item> <item ItemID="2" ParentID="0">item2</item> <item ItemID="3" ParentID="2">Item3</item> <item ItemID="4" ParentID="3">Item4</item> <item ItemID="5" ParentID="2">item5</item> <item ItemID="6" ParentID="0">item6</item> </x> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="item" match="item" use="@ItemID"/> <xsl:template match="item"> <xsl:param name="l" select="1"/> <xsl:param name="content" select="@*|node()"/> <xsl:choose> <xsl:when test="@ParentID=0"> <xsl:element name="itemL{$l}"> <xsl:copy-of select="$content"/> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="key('item',@ParentID)"> <xsl:with-param name="l" select="$l+1"/> <xsl:with-param name="content" select="$content"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> $ saxon level.xml level.xsl <?xml version="1.0" encoding="utf-8"?> <itemL1 ItemID="1" ParentID="0">item1</itemL1> <itemL1 ItemID="2" ParentID="0">item2</itemL1> <itemL2 ItemID="3" ParentID="2">Item3</itemL2> <itemL3 ItemID="4" ParentID="3">Item4</itemL3> <itemL2 ItemID="5" ParentID="2">item5</itemL2> <itemL1 ItemID="6" ParentID="0">item6</itemL1>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] using parameters to identify , fiberartisan | Thread | [xsl] Searching in Sub-children fro, Houman Khorasani |
[xsl] Searching in Sub-children fro, Houman Khorasani | Date | Re: [xsl] Searching in Sub-children, David Carlisle |
Month |