title: using position() in XSLT transformation
body: <p>I am trying to transform following XML </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;catalog&gt;
      &lt;cd QualifyingCode="1"&gt;
          &lt;title&gt;title1&lt;/title&gt;
          &lt;artist&gt;artist1&lt;/artist&gt;
      &lt;/cd&gt;
      &lt;cd QualifyingCode="1"&gt;
          &lt;title&gt;title2&lt;/title&gt;
          &lt;artist&gt;artist2&lt;/artist&gt;
      &lt;/cd&gt;
      &lt;cd QualifyingCode="2"&gt;
          &lt;title&gt;title3&lt;/title&gt;
          &lt;artist&gt;artist3&lt;/artist&gt;
      &lt;/cd&gt;
      &lt;cd QualifyingCode="2"&gt;
          &lt;title&gt;title4&lt;/title&gt;
          &lt;artist&gt;artist4&lt;/artist&gt;
      &lt;/cd&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>Using floowing XSLT</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
    &lt;body&gt;
    &lt;h2&gt;My CD Collection&lt;/h2&gt;
      &lt;table border="1"&gt;
        &lt;tr bgcolor="#9acd32"&gt;
          &lt;th style="text-align:left"&gt;Title&lt;/th&gt;
          &lt;th style="text-align:left"&gt;Artist&lt;/th&gt;
          &lt;th style="text-align:left"&gt;ID&lt;/th&gt;
        &lt;/tr&gt;
        &lt;xsl:for-each select="catalog/cd"&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;xsl:value-of select="title"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;xsl:value-of select="artist"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;xsl:value-of select="position()"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;/xsl:for-each&gt;
      &lt;/table&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>I am getting the position as 1,2,3,4 using the position(). What I want is output for the position() should be 1,2,1,2 based on "QualifyingCode" attribute.</p>
  
  <p>so my current output is :</p>
  
  <pre><code>My CD Collection
  Title   Artist  ID
  title1  artist1 1
  title2  artist2 2
  title3  artist3 3
  title4  artist4 4
  </code></pre>
  
  <p>and my expected output is </p>
  
  <pre><code> My CD Collection
      Title   Artist  ID
      title1  artist1 1
      title2  artist2 2
      title3  artist3 1
      title4  artist4 2
  </code></pre>