[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: using parameters to identify element levels
> 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>
|
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
|