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

position() return's only even numbers for nested eleme

Subject: position() return's only even numbers for nested elements
From: DURDINA Michal <durdina@xxxxxxxx>
Date: Fri, 9 May 2003 17:51:33 +0200
xsl position even
Hello,
please take a look at this xsl fragment, maybe you find a simple explanation
to strange behaviour of position() function for nested elements.

Consider this input xml:
<uml>
  <package id="1"/>
  <package id="2"/>
  <package id="3">
    <package id="31"/>
    <package id="32"/>
  </package>
  <package id="4">
    <package id="41">
      <package id="411"/>
      <package id="412"/>
      <package id="413"/>
    </package>
  </package>
  <package id="5"/>
</uml>

Now I want to print position of every single 'package' element:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="uml">
    <result>
      <xsl:apply-templates select="package"/>
    </result>
  </xsl:template>
  
  <xsl:template match="package">
    <xsl:copy>
      <xsl:copy-of select="@id"/>
      <xsl:attribute name="position"><xsl:value-of
select="position()"/></xsl:attribute>
      <xsl:apply-templates/>
    </xsl:copy>    
  </xsl:template>

</xsl:stylesheet>

And the result under Saxon and Xalan is:
<result>
  <package id="1" position="1"/>
  <package id="2" position="2"/>
  <package id="3" position="3">
    <package id="31" position="2"/>
    <package id="32" position="4"/>
  </package>
  <package id="4" position="4">
    <package id="41" position="2">
      <package id="411" position="2"/>
      <package id="412" position="4"/>
      <package id="413" position="6"/>
    </package>
  </package>
  <package id="5" position="5"/>
</result>

Why all nested 'package' element have even positions (2, 4, 6, ...) but
top-level 'package' elements positions behaves right (1, 2, 3,...) ???

When I replace <xsl:apply-templates/> with <xsl:apply-templates
select="packages"/>, then it works right also for nested 'packages'
elements.

I''ll be thankful for every explanation.

Michal

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.