I have an XML like this: 

```
<V>
  <W>
    <X>1</X> 
  </W>
  <W>
    <Y>1</Y> 
  </W>
  <W>
    <X>1555</X> 
  </W>
  <W>
    <X>1</X> 
  </W>
</V>

```

I want to make it something like this:

```
<entity ID="start">
    <f ID="NewField">0001</f>
    <f ID="NewField">0001</f>
    <f ID="NewField">0002</f>
    <f ID="NewField">0003</f>
</entity>

```

When the field is V/W/X then `NewField` should be incremented by 1 as many times the tag V/W/X is found.
Similarly for V/W/Y.

The XSL which I am using is

```
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<entity ID="start">
    <xsl:for-each select="V/W">
        <xsl:if test="X">
            <xsl:variable name="my_var">
                <xsl:value-of select="concat('000',position())"/>
            </xsl:variable>
            <f ID="NewField"><xsl:value-of  select="$my_var"/></f>
        </xsl:if>
        <xsl:if test="Y">
            <xsl:variable name="my_var">
                <xsl:value-of select="concat('000',position())"/>
            </xsl:variable>
            <f ID="NewField"><xsl:value-of  select="$my_var"/></f>
        </xsl:if>
    </xsl:for-each>
</entity>
</xsl:template>
</xsl:stylesheet>

```

but it gives me a wrong result, something like this:

```
<entity ID="start">
  <f ID="NewField">0001</f>
  <f ID="NewField">0002</f> 
  <f ID="NewField">0003</f> 
  <f ID="NewField">0004</f> 
</entity>

```