XSLT: Count only when value greater than nul -
all,
this question related xslt 1.0
is there way count nodes specific value greater null? use sum function total of this:
<servicelevels> <servicelevel> <key>0..20</key> <value>100.00</value> </servicelevel> <servicelevel> <key>20..30</key> <value>0.00</value> </servicelevel> <servicelevel> <key>30..40</key> <value>0.00</value> </servicelevel> <servicelevel> <key>40..50</key> <value>0.00</value> </servicelevel> <servicelevel> <key>50..60</key> <value>0.00</value> </servicelevel> <servicelevel> <key>60..70</key> <value>0.00</value> </servicelevel> <servicelevel> <key>70+</key> <value>98.33</value> </servicelevel> </servicelevels>
to find sum of value keys, use:
<xsl:value-of select="sum(servicelevels/servicelevel/value | servicelevels/servicelevel/value)"/>
what produces sum of 198.33 calculate the average of 7 nodes use xsl:value-of select="count(....)"
calculates 28.333 want find average nodes contain actual values in example 2 nodes creates average of 99.165.
is there (relative simple) way of achieving this?
the xml contains 7 key values
select value
nodes content (as number) greater zero:
<xsl:variable name="values" select="servicelevels/servicelevel/value[number(.) > 0]"/>
average:
<xsl:value-of select="sum($values) div count($values)"/>
Comments
Post a Comment