XSLT: Getting the position of an element in the new XML
<p>I need to add a growing, not-resetting sequence number to ALL of the elements in the XML based in their new position. I tried using this as an attribute</p>

<pre><code>&lt;xsl:value-of select="count(preceding::* | ancestor::*) + 1" /&gt;
</code></pre>

<p>However, this will result the sequence numbers being based on the element's original location in the document. </p>

<p>My original XML, created from multiple XMl files with "copy-of":</p>

<pre><code>&lt;title&gt;
  &lt;article&gt;
    &lt;paragraph&gt;
      &lt;subparagraph&gt;
      &lt;/subparagraph&gt;
    &lt;/paragraph&gt;
  &lt;/article&gt;
&lt;/title&gt;
</code></pre>

<p>I remove the unneccessary 'article' tag from the new XML with XSLT. The result is then this:</p>

<pre><code>&lt;title id="1"&gt;
  &lt;paragraph id="3"&gt;
    &lt;subparagraph id="4"&gt;
    &lt;/subparagraph&gt;
  &lt;/paragraph&gt;
&lt;/title&gt;
</code></pre>

<p>The result I desire:</p>

<pre><code>&lt;title id="1"&gt;
  &lt;paragraph id="2"&gt;
    &lt;subparagraph id="3"&gt;
    &lt;/subparagraph&gt;
  &lt;/paragraph&gt;
&lt;/title&gt;
</code></pre>

<p>What is the optimal way to achieve this?</p>