title: xsl : Incrementing a global variable
body: <p>I know the fact that variables in XSL are immutable. But in my scenario, I want to increment a global variable and use the value later. Is there any other way by which this can be done? I have added enough comments in the code to make my question more clear. Please note I am using XSLT 1.0</p>
  
  <pre><code>&lt;xsl:variable name="counter"&gt;0&lt;/xsl:variable&gt;
  &lt;xsl:template match="/"&gt;
   &lt;xsl:for-each select="Condition_ABC"&gt;
    &lt;xsl:variable name="returnValue"&gt; &lt;!--returnValue is the return value from the named template GetValue --&gt;
     &lt;xsl:call-template name="GetValue"/&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:if test="not($returnValue= '')"&gt;
     &lt;!-- If the returned value is not null
          Here I want to add the increment logic, something like this 
          $counter = $counter+ 1  --&gt;
     &lt;xsl:value-of select="."/&gt;
    &lt;/xsl:if&gt;
   &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="some_pattern"&gt;
   &lt;Attribute&gt;
    &lt;!-- the final 'counter' value from above xsl block needs to be outputted here --&gt;
    &lt;xsl:value-of select="$counter"/&gt;
   &lt;/Attribute&gt;
  &lt;/xsl:template&gt;
  </code></pre>