How to sum() positive/negative numbers in XSLT?

clarabeijing

New Member
To sum a series of values (positive or negative) use the sum() function in XPath.In this example we get transactions from an XML source and puts it into a variable. Then we sum it up in the end.XML Source:\[code\]<month month="04"> <balance in="987000,00" acnt="1100"/> <balance in="167440,00" acnt="1280"/> <balance in="1098000,00" acnt="1380"/> <balance in="575000,00" acnt="1460"/> <balance in="-75000,00" acnt="1469"/> ...</month>\[/code\]XSLT: This results in the following structure:\[code\]<account> <month month="name"> <in>987000.00</in> </month> ...</account>\[/code\]To sum the values we use the following XSLT snippet:\[code\]<xsl:value-of select="sum(ext:node-set($sumSet)//in)"/>\[/code\]
 
Back
Top