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

Re: using parameters to identify element levels

Subject: Re: using parameters to identify element levels
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 4 Dec 2006 16:22:41 GMT
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>

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-2013 All Rights Reserved.