title: XSLT : How to assign a value to global variable
body: <p>Just I want to do simple addition. When i iterate values, just i want to do sum and print that value.</p>
  
  <p>This is the way which i tried. But it is just printing 0.</p>
  
  <p>This is my xml.</p>
  
  <pre><code>        &lt;t:Employee&gt;
          &lt;t:Earnings_Deductions&gt;
              &lt;t:Amount t:PriorValue=""&gt;4000&lt;/t:Amount&gt;
          &lt;/t:Earnings_Deductions&gt;
          &lt;/t:Employee&gt;
          &lt;t:Employee&gt;
          &lt;t:Earnings_Deductions&gt;
              &lt;t:Amount t:PriorValue=""&gt;4000&lt;/t:Amount&gt;
          &lt;/t:Earnings_Deductions&gt;
          &lt;/t:Employee&gt;
          &lt;t:Employee&gt;
          &lt;t:Earnings_Deductions&gt;
              &lt;t:Amount t:PriorValue=""&gt;4000&lt;/t:Amount&gt;
          &lt;/t:Earnings_Deductions&gt;
          &lt;/t:Employee&gt;
  </code></pre>
  
  <p>I want to add all the Amount and show it like this.</p>
  
  <pre><code>&lt;item&gt;&lt;p&gt;700000&lt;/p&gt;&lt;/item&gt;
  
  &lt;xsl:variable name="Total_Amount" select="0" /&gt;
          &lt;item&gt;
  
          &lt;xsl:for-each select="//*[local-name() = 'Employee']"&gt;
          &lt;xsl:for-each select="//*[local-name() = 'Earning_Deductions']"/&gt;
          &lt;xsl:variable name="amount"&gt;&lt;xsl:value-of select="//*[local-name() = 'Amount']"/&gt;&lt;/xsl:variable&gt;
          &lt;xsl:value-of select="$Total_Amount"&gt;&lt;xsl:value-of select="$Total_Amount + $amount"/&gt;&lt;/xsl:value-of&gt;
          &lt;/xsl:for-each&gt;
          &lt;p&gt;&lt;xsl:value-of select="$Total_Amount"&gt;&lt;/xsl:value-of&gt;&lt;/p&gt;
          &lt;/item&gt;
  </code></pre>
  
  <p>I am new to xslt. Please help me to solve this problem.</p>