I am trying to output a table which lists a customer's payments whilst keeping a running total. A section of my XML is as follows:

[CODE]

1 2009-03-16 22 4 2009-02-12 35 2 2009-05-17 41 [/CODE] I have included the following code to sort the output into date order: [CODE] [/CODE] In attempting to output the table I have written the following code: [CODE] [/CODE] However, when accumulating the running total the calculations are done in the order of the xml output. How would I change this so that the calculations are done (and displayed) by the earliest date first?? Many Thanks