This is the same as any other problem summing over a computed value (the classical example is summing over price*quantity; another example is summing the prices after removing a currency symbol).

The solutions break down into three categories:

(a) recursive solutions: walk the sequence of nodes in a step-by-step recursive scan, keeping track of the running total as you go

(b) two-pass solutions: compute the values to be totalled in the first pass over the data (e.g. in an extra attribute), total them using the sum() function in the second pass

(c) reuse an existing solution that's already been implemented: this problem is very easy do solve using Dimitre Novatchev's FXSL library, once you've worked out how to install this library.

Michael Kay

http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference