I'm getting what appears to be erroneous counts of preceding tags. This is occurring with
both Instant Saxon and full Saxon. Included below are sample
input XML and XSLT files. I'm expecting the following output (generated by msxsl):
 
1
2
3
4
 
What I'm getting from Saxon is:
 
1
1
3
3
 
On the second and the fourth instance of the <index> tag in my code, saxon seems to be ignoring
the immediately preceding instance of <index>.   While paring down my source to include in this
email, I found that if the index tag were an empty tag (<index/>), the count worked as expected,
with output identical to that produced by msxsl.  The XML that follows is what I found to be the
minimal to produce these results.  For example, if either the first or second instance of the
<index> tag were promoted one level in the document tree, the output for the second count
would be correct.  The names of the tags seemed to make no difference, only the relative
location of the <index> tags to each other, as if, from the context of the second and fourth
instances of <index>, the preceding::index[1] tag is in a blind spot.
 
<?xml version="1.0"?>
<helpsystem>
 <p>
  <!-- FIRST OCCURRENCE OF INDEX --><index><text value="placeholder"/></index>
 </p>
 <vl>
  <vi>
   <test/>
   <name>
    <wtf>
     <!-- SECOND OCCURRENCE OF INDEX --><index><text value="placeholder"/></index>
    </wtf>
   </name>
   </vi>
 </vl>
 <p>
  <!-- THIRD OCCURRENCE OF INDEX --><index><text value="placeholder"/></index>
 </p>
 <vl>
  <vi>
   <value>Authentication Failed.</value>
   <detail>
    <p>
     <!-- FOURTH OCCURRENCE OF INDEX --><index><text value="placeholder"/></index>
    </p>
   </detail>
  </vi>
 </vl>
</helpsystem>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
<xsl:output method="xml" omit-xml-declaration="yes" encoding="iso-8859-1" version="1.0" indent="no"/>
 
<xsl:strip-space elements="*"/>
 
<xsl:template match="/">
 <xsl:text disable-output-escaping="yes"><!-- apologies, Mike, for using the dreaded d-o-e :-) -->
</xsl:text>
 <xsl:for-each select="//index">
  <xsl:value-of select="count(preceding::index) + 1"/>
  <xsl:text disable-output-escaping="yes">
</xsl:text>
 </xsl:for-each>
 <xsl:text disable-output-escaping="yes">
</xsl:text>
</xsl:template>
 
</xsl:stylesheet>
Thanks.
Mark Wilgus
Technical Writer
Cisco Systems