Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] using parameters to identify element levels

From: fiberartisan@---------
To:
Date: 12/4/2006 3:42:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent