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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of values

Status
Not open for further replies.

Azhrarn

Programmer
Oct 28, 2003
2
0
0
US
Hi guys, hope you can help.
I ve been trying this in several ways but to no avail.
I have the following:

[...]
<finance>
<incomes>
<account name=&quot;X&quot; value=&quot;-84&quot; />
<account name=&quot;Y&quot; value=&quot;12&quot; />
<account name=&quot;Z&quot; value=&quot;-98&quot; />
<account name=&quot;S&quot; value=&quot;-10&quot; />
</incomes>
<costs>
<account name=&quot;A&quot; value=&quot;7&quot; />
</costs>
</finance>

how do I sum together the positive &quot;value&quot; values of <incomes> with the positive of <costs> and vice versa the negative value with the negative?
have tried
<xsl:variable name=&quot;sumOfIncomes&quot;>
<xsl:value-of select=&quot;sum(//incomes/account[@value][@value > 0])&quot; />
</xsl:variable>

and something like using a recursive sum with
<xsl:value-of select=&quot;sum(//incomes/account[$position]/@value[(//incomes/account[$position]/@value > 0])&quot; />

Please help, I ve lost days on it so far...
Thanks a million in advance
Regards
Azh
 
I don't fully understand what you are trying to do. In the example you gave what should the results be?

If you are looking for 19 and -192 then something like

<xsl:value-of select=&quot;sum(.//account[@value > 0])&quot;/>

(This assumes ./ is the finance node)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top