XSLT, sum all negative nodes and all nodes as an absolute value

I can use SUM (xpath) to summarize all node values, but I also have a requirement to sum all positive node values, all negative node values ​​and all node values ​​that treat them as absolute values. Is this possible with XSLT?

+4
source share
2 answers

To summarize all the positive node values, you can do:

<xsl:value-of select="sum(//*[. &gt; 0])" /> 

To summarize all negative node values, you can do:

 <xsl:value-of select="sum(//*[. &lt; 0])" /> 

To sum the absolute values ​​of numbers, you can do:

 <xsl:value-of select="sum(//*[. &gt; 0]) - sum(//*[. &lt; 0])" /> 
+3
source

Cm.

xslt 1 and the sum function

for a list of common approaches to the problem

+2
source

Source: https://habr.com/ru/post/1390888/


All Articles