Reputation: 15
sum the value the attribute in the element.How can do with the function SUM()
?
My version of xslt
is version1.0.
For example:
<catalog>
<cds>
<cd id='1' price='10'/>
<cd id='2' price='20'/>
<cd id='3' price='30'/>
<cd id='3' price='-'/>
</cds>
</catalog>
the result is 10+20+30=60,but skip the attribute with '-'
Upvotes: 1
Views: 25
Reputation: 167401
You can use a predicate sum(/catalog/cds/cd/@price[number() = number()])
as the condition number() = number()
will only be true for values convertible to numbers: https://xsltfiddle.liberty-development.net/ej9EGd8
Upvotes: 2