Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-assigning a variable's value

Status
Not open for further replies.

Faheemi

Programmer
Sep 2, 2001
59
HK
Hi there,

I am very new to XSL. I wanted to do the following:

Assign a variable named "Total_Amount" in the global scope.

Then I loop through each child nodes using

<xsl:for-each select=&quot;RESULTSET/ROW&quot;>

and add the node value of &quot;Amount&quot; to the global &quot;Total_Amount&quot; variable and finally display it as Grand Total at the end.

<xsl:variable name=&quot;Total_Amount&quot;><xsl:value-of select=&quot;$Total_Amount + $Amount&quot;/></xsl:variable>

But the global variable is not being modified. It seems that it creates a local variable with the same name of the global variable.

Also it seems that a variable within the for loop is not global even within each iteration of the loop.

I have no idea how to work this around.
Please shed some lights on my issue.

Thanks a lot.
Hameed

 
Hi Hameed,

Variables in XSL can not be reassigned, thus meaning that once you've assigned a value to a variable, you can't change it anymore.

Try to use the sum() function instead.

Good luck!

Jordi Reineman
 
Thanks Jordi,

I was finally managed to use sum() function to get the result.

Hameed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top