title: Find the position of an element within its parent with XSLT / XPath
body: <p>Apart from rewriting a lot of XSLT code (which I'm not going to do), is there a way to find the position of an element within its parent, when the context is arbitrarily set to something else? Here's an example:</p>
  
  <pre><code>&lt;!-- Here are my records--&gt;
  &lt;xsl:for-each select="/path/to/record"&gt;
    &lt;xsl:variable name="record" select="."/&gt;
  
    &lt;!-- At this point, I could use position() --&gt;
    &lt;!-- Set the context to the current record --&gt;
    &lt;xsl:for-each select="$record"&gt;
  
      &lt;!-- At this point, position() is meaningless because it's always 1 --&gt;
      &lt;xsl:call-template name="SomeTemplate"/&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:for-each&gt;
  
  
  &lt;!-- This template expects the current context being set to a record --&gt;
  &lt;xsl:template name="SomeTemplate"&gt;
  
    &lt;!-- it does stuff with the record's fields --&gt;
    &lt;xsl:value-of select="SomeRecordField"/&gt;
  
    &lt;!-- How to access the record's position in /path/to or in any other path? --&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p><strong>NOTE:</strong> This is a simplified example. I have several constraints keeping me from implementing obvious solutions, such as passing new parameters to <code>SomeTemplate</code>, etc. I can really only modify the internals of <code>SomeTemplate</code>.</p>
  
  <p><strong>NOTE:</strong> I'm using Xalan 2.7.1 with <a href="http://www.exslt.org/">EXSLT</a>. So those tricks are available</p>
  
  <p>Any ideas?</p>