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!

Confused on how to navigate nodes while using functions

Status
Not open for further replies.

Desidirius

Programmer
Aug 31, 2006
2
US
So I'm setting up a stats XML, and I'd like to track each player's game-by-game stats and then provide a sum of their statistics. The XML file looks something like this in my head:

<roster>
<player1>
<game1>
<stat1>
</stat1>
<stat2>
</stat2>
</game1>
<game2>
<stat1>
</stat1>
<stat2>
</stat2>
</game2>
</player1>
<player2>
<game1>
<stat1>
</stat1>
<stat2>
</stat2>
</game1>
<game2>
<stat1>
</stat1>
<stat2>
</stat2>
</game2>
</player2>
</roster>

How would I structure a function to sum up stat1 player-by-player, rather than for the entire roster?
 
Think in these terms...
Code:
<xsl:for-each select="/roster/*">
<xsl:text>The sum for </xsl:text>
<xsl:value-of select="local-name(.)"/>
<xsl:text> is </xsl:text>
<xsl:value-of select=format-number(sum(*/stat1), '####')"/>
</xsl:for-each>
This iterates over each child element of <roster> using the for-each, and uses the XPath sum function to sum the nodeset values of all the <stat1> elements which are subordinate to the child elements (<gamen>) of the context node of the for-each (<playerm>).

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top