[xsl] position() return's only even numbers for nested elements

Subject: [xsl] position() return's only even numbers for nested elements
From: DURDINA Michal <durdina@xxxxxxxx>
Date: Fri, 9 May 2003 17:51:33 +0200
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:
  <package id="1"/>
  <package id="2"/>
  <package id="3">
    <package id="31"/>
    <package id="32"/>
  <package id="4">
    <package id="41">
      <package id="411"/>
      <package id="412"/>
      <package id="413"/>
  <package id="5"/>

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

<xsl:stylesheet version="1.0"

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


And the result under Saxon and Xalan is:
  <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 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 id="5" position="5"/>

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'

I''ll be thankful for every explanation.


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

Current Thread