title: In XSLT how do I increment a global variable from a different scope?
body: <p>I am processing an XML file where I want to keep count of the number of nodes, so that I can use it as an ID as I write new nodes.</p>
  
  <p>At the moment I have a global variable called 'counter'. I am able to access it within a template, but I haven't found a way of manipulating it within a template.</p>
  
  <p>Here is a condensed version of my XSLT file:</p>
  
  <pre><code>&lt;xsl:variable name="counter" select="1" as="xs:integer"/&gt;
  
  &lt;xsl:template match="/"&gt; 
     &lt;xsl:for-each select="section"&gt;
        &lt;xsl:call-template name="section"&gt;&lt;/xsl:call-template&gt;
     &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="section"&gt;
  
     &lt;!-- Increment 'counter' here --&gt;
  
     &lt;span class="title" id="title-{$counter}"&gt;&lt;xsl:value-of select="title"/&gt;&lt;/span&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Any suggestions how to go from here?</p>