0

I want to print sum of the cost of this all entree. So what mathematically:

<commande date="2012-12-05" numero="c1001">
    <entree ref="p1012732NC" prix="39.98" quantite="2" />
    <entree ref="p2203633" prix="149" quantite="1" />
    <entree ref="p2103625E" prix="249" quantite="1" />
    <entree ref="p3317" prix="325" quantite="2" />
</commande>

sum(quantite*prix)

How can I do that with xsl? I've tried using variables with for-each loop inside and normal valye-of. but I'm still getting some strange results (I won't add this code since it's just bad).

René Höhle
  • 26,716
  • 22
  • 73
  • 82
Hassan Bendouj
  • 311
  • 1
  • 8
  • 14

1 Answers1

1

Assuming the current context node is the commande element, in XSLT 2.0 it should be as simple as

<xsl:value-of select="sum(entree/(xs:double(@quantite) * xs:double(@prix)))" />

(you probably don't even need the xs:double conversions)

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183