XSLTGeneral questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
You could get a long way just by googling for "XSLT sum of price times quantity".
In XSLT 2.0 the solution is sum(item/(@price * @quantity))
In XSLT 1.0 it's much harder. The only clean solution is a recursive traversal of the items in which you pass the accumulated sum as a parameter and add in the value of @price * @quantity before making the recursive call to process the next item. You'll often find this in XSLT books as a textbook example of recursive template processing.
Of course, sum(item/@quantity * item/@price) doesn't work. You can't take a set of attribute nodes and multiply it by another set of attribute nodes.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference