DIGIFORMS
Digiforms Designer Documentation
 
 
 
 
 
 
Help by samples
 
 
 
Capture or output data in a defined layout
 
Extensible Markup Language
Summing values
Summing values with sum() Function
Usage
The sum() function returns the sum of all nodes in the specified node-set ( xpath ). Each node is first converted to a number value before summing.
Syntax
<xsl:value-of select="sum( xpath )"/>
xslt
attribute="{sum( xpath )}"
attribute template
Example
Summing values (simple)
This example demonstrates summing all item element's value attribute.
<?xml version="1.0"?> <root> <item value="100"></item> <item value="300"></item> <item value="200"></item> </root>
xml
<xsl:value-of select="sum(//item/@value)"/> Output: 600.0
xslt
Example
Calculating order total
This example demonstrates how to calculate order total ( sum of price times quantity for multiple orderlines )
This example requires using XSLT 2.0
<?xml Version="1.0"?> <order> <orderline> <itemPrice>100</itemPrice> <itemQty>2</itemQty> </orderline> <orderline> <itemPrice>50</itemPrice> <itemQty>1</itemQty> </orderline> </order>
xml
<xsl:value-of select="sum(//orderline/(itemPrice * itemQty))"/> Output: 250.0
xslt