Performing running totals in XSL is a horrible pain. A google shows countless techniques, countless XSL extensions, and suggestions to ratify the standard itself.
In one of my Win Forms applications I employ the XML->XSLT->XHTML pattern for the reporting facilities. The reporting needs were, at least initially, a rather ancillary feature to the application. All was well until the customer requested verbose reporting from the log files created by the application, including running totals. A bit of googling and I was able to whip up a little incantation using XSL templates. The XML data represents the log file of the application and has a structure like the following:
<PurchaseOrder PONumber="13579">
<Item PartNumber="12345" Quantity="2" Price="10" />
<Item PartNumber="54321" Quantity="2" Price="26.65" />
</PurchaseOrder>
Pretty simple really. The trouble comes when trying to aggregate the totals for each PurchaseOrder node by multiplying the quantity by the price. I tried many variations of the template incantations, but all of them were unacceptably slow with MSXML and Sablotron. I ended up employing a variation of Martin Fowler's Two-Step View pattern by creating an interim stylesheet that would aggregate the totals for me without using templates.
When applying the interim stylesheet I would simply for-each the Item nodes and multiply the quantity by the price. The resultant XML has a structure like the following:
<PurchaseOrder PONumber="349167">
<Item PartNumber="764677017241" Total="20"/>
<Item PartNumber="764677042885" Total="53.3"/>
</PurchaseOrder>
I now have a total for each line item that I can use to total purchase orders using the standard XPath functions. This reduced the total display time of the report from literally minutes to just a few seconds. I'm certain someone with more XSL/XPath knowledge than myself could derive a "pure" XSL/XPath solution, but I could find nothing as computationally palatable as the above.