hunt
hunt

Reputation: 15

the sum function in XSLT(sum the attribute in the element)

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

Answers (1)

Martin Honnen
Martin Honnen

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

Related Questions