[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

using parameters to identify element levels

Subject: using parameters to identify element levels
From: fiberartisan@xxxxxxxxx
Date: Mon, 4 Dec 2006 10:41:49 -0500
xsl element name parameter
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.