title: Create sequence number in xslt
body: <p>Input XML:</p>
  
  <pre><code>&lt;doc&gt;
   &lt;section&gt;
    &lt;para&gt;Paragraph 1&lt;/para&gt;
    &lt;para&gt;Paragraph 2&lt;/para&gt;
    &lt;para&gt;Paragraph 3&lt;/para&gt;
   &lt;/section&gt;
    &lt;para&gt;Paragraph 4&lt;/para&gt;
    &lt;para&gt;Paragraph 5&lt;/para&gt;
    &lt;para&gt;Paragraph 6&lt;/para&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>Required output:</p>
  
  <pre><code>&lt;book&gt;
  &lt;section&gt;
    &lt;p class="para" id="0001"&gt;Paragraph 1&lt;/p&gt;
    &lt;p class="para" id="0002"&gt;Paragraph 2&lt;/p&gt;
    &lt;p class="para" id="0003"&gt;Paragraph 3&lt;/p&gt;
   &lt;/section&gt;
    &lt;p class="para" id="0004"&gt;Paragraph 4&lt;/p&gt;
    &lt;p class="para" id="0005"&gt;Paragraph 5&lt;/p&gt;
    &lt;p class="para" id="0006"&gt;Paragraph 6&lt;/p&gt;
   &lt;/book&gt;
  </code></pre>
  
  <p>I tried with following XSL but I am not getting desired output. Anyone could help me in this?</p>
  
  <pre><code>&lt;xsl:template match="para"&gt;
      &lt;xsl:variable name="count" select="position()"/&gt;
      &lt;p class="para" id="{$count}"&gt;
          &lt;xsl:apply-templates/&gt;
      &lt;/p&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The result I am getting is:</p>
  
  <pre><code>&lt;p class="para" id="2"&gt;Paragraph 1&lt;/p&gt;
  &lt;p class="para" id="4"&gt;Paragraph 2&lt;/p&gt;
  &lt;p class="para" id="6"&gt;Paragraph 3&lt;/p&gt;
  
      &lt;p class="para" id="4"&gt;Paragraph 4&lt;/p&gt;
      &lt;p class="para" id="6"&gt;Paragraph 5&lt;/p&gt;
      &lt;p class="para" id="8"&gt;Paragraph 6&lt;/p&gt;
  </code></pre>