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

XSL: Adding values to create a total

Status
Not open for further replies.

JoeMcGarvey

Programmer
Oct 31, 2002
47
US
Hi Sportsfans - I am stuck on an XSL problem. I have multiple XML nodes (games) that each have a value: wins, losses, ties.

In my xsl I set three variables at the top of the style sheet:

<xsl:variable name=&quot;wins&quot;>0</xsl:variable>
<xsl:variable name=&quot;losses&quot;>0</xsl:variable>
<xsl:variable name=&quot;ties&quot;>0</xsl:variable>

Then I call a template to loop through the nodes and total the number of wins, ties, and losses. The loop code returns an unexpected result. Here is the sample for wins:

<xsl:template match='entity' mode='record'>
<xsl:if test=&quot;number(HTScore)&gt;number(ATScore)&quot;>
<xsl:variable name=&quot;wins&quot; select=&quot;number($wins+1)&quot;/>
<xsl:value-of select=&quot;number($wins)&quot;/>
</xsl:if>
</xsl:template>

There are 4 total wins in the nodes, but &quot;$wins&quot; returns &quot;1111&quot;. So the loop is appending a value of the win (1) each time, instead of performing the equation.

Any ideas what I am doing wrong?
 
Nope... that doesn't work. Same result.

The variable is incrementing by 1 from my original global value of 0, though.

I can do this with a simple Javascript, but want pure XSL.
 
why won't you use the sum function , and sum nodes which answer to the criteria ...

I see that you just wanna count the number of wins , so you can have for each win, a node in XML .. something like &quot;WINVALUE&quot; which will always be with value of 1 .
so you just sum the values of WINVALUE nodes , when your criteria is met .

something more simpler :
I think XSLT has the count function ...
( though I've never used it )
so check it out .

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top