sum Function (XPath)
Collapse the table of content
Expand the table of content

sum Function (XPath)

Returns the sum of all nodes in the node-set. Each node is first converted to a number value before summing.

          number sum(node-set)

This example demonstrates the XPath expression sum(//a). It returns 6, which is the sum of the numbers in <a> elements.

XML File (as.xml)

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="sum.xsl"?>

XSLT File (sum.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"

<xsl:template match="/">
   <xsl:value-of select='sum(//a)'/>


Formatted Output


Processor Output

<?xml version="1.0" encoding="UTF-16"?>6

Build Date:

© 2016 Microsoft