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

Count preceeding sibling but in different element

Subject: Count preceeding sibling but in different element
From: "Taco Fleur" <taco@xxxxxxxxxxxxx>
Date: Fri, 5 Aug 2005 16:12:50 +1000
 Count preceeding sibling but in different element
I am wanting to count all preceeding sibling (steps) but they could be
in different elements

<element1>
  <element2>
     <step/>
     <step/>
  </element2>
  <element3>
     <step/>
  </element3>
  <element4>
     <step/>
     <step/>
     <step/>
  </element4>
</element1>

The output I am after is

<element1>
  <element2>
     <step number="1" />
     <step number="2"/>
  </element2>
  <element3>
     <step number="3"/>
  </element3>
  <element4>
     <step number="4"/>
     <step number="5"/>
     <step number="6"/>
  </element4>
</element1>

I have have the following which works fine on every step within an
element, i.e.

  <element3>
     <step/>
  </element3>
  <element4>
     <step/>
     <step/>
     <step/>
  </element4>

Would become

  <element3>
     <step number="1"/>
  </element3>
  <element4>
     <step number="1"/>
     <step number="2"/>
     <step number="3"/>
  </element4>

<xsl:template match="step">
 <xsl:copy>
  <xsl:copy-of select="@*" />
  <!-- Calculate the step number -->
  <xsl:attribute name="number">
   <xsl:value-of select="count( preceding-sibling::step ) + 1" />
  </xsl:attribute>
  <xsl:apply-templates />
 </xsl:copy>
</xsl:template>

Can anyone help?
Thanks
________________________________
Taco Fleur - E-commerce Development Manager
Shelco Searches & Services
An Authorised ASIC Information Broker
www.shelco.com.au <blocked::http://www.shelco.com.au>
Ph: + 61 7 3236 2605

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.