title: Determining the context for position() in a template with multiple predicates
body: <p>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):</p>
  
  <pre><code>&lt;xsl:template match="//chapter/body/*[matches(name(), '^toc')][crossref][not(crossref/@idref='cip' or crossref/@idref='copy')]"&gt;
    &lt;xsl:variable name="curr_id" select="crossref/@idref"/&gt;
    &lt;xsl:element name="location"&gt;
      &lt;xsl:attribute name="id"&gt;&lt;xsl:value-of select="$curr_id"/&gt;&lt;/xsl:attribute&gt;
      &lt;xsl:attribute name="order"&gt;&lt;xsl:value-of select="position()"/&gt;&lt;/xsl:attribute&gt;
      &lt;xsl:element name="label"&gt;
          &lt;text&gt;&lt;xsl:value-of select="."/&gt;&lt;/text&gt;
      &lt;/xsl:element&gt;
    &lt;/xsl:element&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The XML looks a bit like this:</p>
  
  <pre><code>&lt;chapter id="toc"&gt;
    &lt;body&gt;
      &lt;title&gt;Contents&lt;/title&gt;
      &lt;tocfm&gt;&lt;crossref idref="cip"&gt;Catalog&lt;/crossref&gt;&lt;/tocfm&gt;
      &lt;tocfm&gt;&lt;crossref idref="copy"&gt;Copyright&lt;/crossref&gt;&lt;/tocfm&gt;
      &lt;tocfm&gt;&lt;crossref idref="ded"&gt;Dedication&lt;/crossref&gt;&lt;/tocfm&gt;
      &lt;toc&gt;&lt;crossref idref="prologue"&gt;Prologue&lt;/crossref&gt;&lt;/toc&gt;
      &lt;toc&gt;&lt;crossref idref="pt1"&gt;Book One&lt;/crossref&gt;&lt;/toc&gt;
      &lt;toc&gt;&lt;crossref idref="pt2"&gt;Book Two&lt;/crossref&gt;&lt;/toc&gt;
      &lt;toc&gt;&lt;crossref idref="pt3"&gt;Book Three&lt;/crossref&gt;&lt;/toc&gt;
    &lt;/body&gt;
  &lt;/chapter&gt;
  </code></pre>
  
  <p>My expectation is that the predicate will generate a node set that contains:</p>
  
  <pre><code>&lt;tocfm&gt;&lt;crossref idref="ded"&gt;Dedication&lt;/crossref&gt;&lt;/tocfm&gt;
  &lt;toc&gt;&lt;crossref idref="prologue"&gt;Prologue&lt;/crossref&gt;&lt;/toc&gt;
  &lt;toc&gt;&lt;crossref idref="pt1"&gt;Book One&lt;/crossref&gt;&lt;/toc&gt;
  &lt;toc&gt;&lt;crossref idref="pt2"&gt;Book Two&lt;/crossref&gt;&lt;/toc&gt;
  &lt;toc&gt;&lt;crossref idref="pt3"&gt;Book Three&lt;/crossref&gt;&lt;/toc&gt;
  </code></pre>
  
  <p>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?</p>