I'm having some trouble determining the correct context for a node set. I have a template match that looks a bit like this (using XSL 2.0):
<xsl:template match="//chapter/body/*[matches(name(), '^toc')][crossref][not(crossref/@idref='cip' or crossref/@idref='copy')]">
<xsl:variable name="curr_id" select="crossref/@idref"/>
<xsl:element name="location">
<xsl:attribute name="id"><xsl:value-of select="$curr_id"/></xsl:attribute>
<xsl:attribute name="order"><xsl:value-of select="position()"/></xsl:attribute>
<xsl:element name="label">
<text><xsl:value-of select="."/></text>
</xsl:element>
</xsl:element>
</xsl:template>
The XML looks a bit like this:
<chapter id="toc">
<body>
<title>Contents</title>
<tocfm><crossref idref="cip">Catalog</crossref></tocfm>
<tocfm><crossref idref="copy">Copyright</crossref></tocfm>
<tocfm><crossref idref="ded">Dedication</crossref></tocfm>
<toc><crossref idref="prologue">Prologue</crossref></toc>
<toc><crossref idref="pt1">Book One</crossref></toc>
<toc><crossref idref="pt2">Book Two</crossref></toc>
<toc><crossref idref="pt3">Book Three</crossref></toc>
</body>
</chapter>
My expectation is that the predicate will generate a node set that contains:
<tocfm><crossref idref="ded">Dedication</crossref></tocfm>
<toc><crossref idref="prologue">Prologue</crossref></toc>
<toc><crossref idref="pt1">Book One</crossref></toc>
<toc><crossref idref="pt2">Book Two</crossref></toc>
<toc><crossref idref="pt3">Book Three</crossref></toc>
In other words, all of the toc-like elements that contain a crossref whose idref isn't cip or copy. The template does this in terms of output, but the position function doesn't seem to be working on that node set. Instead, it generates a position of '3' for Dedication. However, if I output the value of the node found by following the predicate with [1], I do get Dedication as that value. So, I'm stumped as to what position is working on. Can anyone enlighten me?