title: Use position of current node to access value of another node
body: <p>I have an xml source that approximates a table layout (output from a program) - a is the table holder, b hold the column headings d, c are the rows and e are the row cells:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
      &lt;a&gt;
      &lt;b&gt;
          &lt;d/&gt;
          &lt;d/&gt;
          &lt;d/&gt;
      &lt;/b&gt;
          &lt;c&gt;
          &lt;e/&gt;
              &lt;e/&gt;
          &lt;e/&gt;
          &lt;/c&gt;
      &lt;/a&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>I have written the following xsl:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-16"?&gt;
  &lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;Lessons&gt;
      &lt;xsl:for-each select="//c"&gt;
          &lt;xsl:call-template name="lesson" /&gt;
      &lt;/xsl:for-each&gt;
      &lt;/Lessons&gt;
  &lt;/xsl:template&gt;
  
  
  &lt;xsl:template name="lesson"&gt;
      &lt;Lesson&gt;
          &lt;Teacher&gt;
              &lt;xsl:value-of select="count(./preceding-sibling::*)+1" /&gt;
              &lt;xsl:value-of select="//b[count(./preceding-sibling::*)+1]" /&gt;
          &lt;/Teacher&gt;
      &lt;/Lesson&gt;
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>The first xsl:value-of of the Teacher element gives me the correct values. I would like the second xsl:value-of to return the value of the heading for that cell i.e. for the first e element that calls the template the first d element is returned and so on. However, it ouputs the value of all of the d elements.</p>