xsl-list
[Top] [All Lists]

[xsl] using parameters to identify element levels

2006-12-04 08:42:15
I'm 99% done with a project and this is the last remaining item.

given the following source:
<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>

(note that the data is properly sequenced; reordering is not necessary)

I'd like the following output:
<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>

The resulting elements do not need to be nested.

What I've been attempting to do is the following (which isn't working)

<xsl:template match="item">
<!-- set initial parameter values -->
<xsl:param name="ItemIDL0">0</xsl:param>
<xsl:param name="ItemIDL1">9999</xsl:param>
<xsl:param name="ItemIDL2">9999</xsl:param>
<xsl:param name="ItemIDL3">9999</xsl:param>
<xsl:param name="ItemIDL4">9999</xsl:param>
                
<xsl:choose>
<!-- match L1 -->
<xsl:when test="@ParentID = $ItemIDL0">
<xsl:call-template name="ItemL1"/>
</xsl:when>
<!-- match L2 -->
<xsl:when test="@ParentID = $ItemIDL1">
<xsl:call-template name="ItemL2"/>
</xsl:when>
<!-- match L3 -->                 
<xsl:when test="@ParentID = $ItemIDL2">
<xsl:call-template name="ItemL3"/>
</xsl:when>
<!-- match L4 -->
<xsl:when test="@ParentID = $ItemIDL3">
<xsl:call-template name="ItemL4"/>
</xsl:when>
<xsl:otherwise>
<xsl:element name="Otherwise">
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>          
</xsl:choose>
</xsl:template>
        
<xsl:template name="ItemL1">
<xsl:param name="ItemIDL1" select="@ItemID"/>
<xsl:element name="ItemL1">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template name="ItemL2">
<xsl:param name="ItemIDL2" select="@ItemID"/>
<xsl:element name="ItemL2">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template name="ItemL3">
<xsl:param name="ItemIDL3" select="@ItemID"/>
<xsl:element name="ItemL3">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template name="ItemL4">
<xsl:param name="ItemIDL4" select="@ItemID"/>
<xsl:element name="ItemL4">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>


And my result is:
<ItemL1>item1</ItemL1>
<ItemL1>item2</ItemL1>
<Otherwise>Item3</Otherwise>
<Otherwise>Item4</Otherwise>
<Otherwise>item5</Otherwise>
<ItemL1>item6</ItemL1>


So it appears that the re-setting of the parameter values isn't
working ... suggestions?

Thanks in advance,

Mary

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>