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

XSLT and SUM()

Status
Not open for further replies.

JoeMcGarvey

Programmer
Oct 31, 2002
47
US
I have been reading about sum() to evaluate some (pardon the pun) nodes. I am very confused and cannot get anything working.

Here is my (simplified) XML:

<entity>
<value>55</value>
</entity>
<entity>
<value>7</value>
</entity>
<entity>
<value>18</value>
</entity>

How do I write my XSL to add the <value> nodes to return the total? Do I use &quot;sum()&quot; with a &quot;call-template&quot; and what should that called template look like?

Thanks!!
 
This will get you the sum which you could use this in any template.

<xsl:value-of select=&quot;sum(//value)&quot;/>


<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:eek:utput method=&quot;html&quot;/>
<xsl:template match=&quot;/&quot;>
<xsl:value-of select=&quot;sum(//value)&quot;/>
</xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top