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:
<Accounts>
<Payment>
<CustomerID>1</CustomerID>
<Date>2009-03-16</Date>
<Amount>22</Amount>
</Payment>
<Payment>
<CustomerID>4</CustomerID>
<Date>2009-02-12</Date>
<Amount>35</Amount>
</Payment>
<Payment>
<CustomerID>2</CustomerID>
<Date>2009-05-17</Date>
<Amount>41</Amount>
</Payment>
I have included the following code to sort the output into date order:
<xsl:apply-templates select="Payment">
<xsl:sort select="Date" />
</xsl:apply-templates>
In attempting to output the table I have written the following code:
<td>
<xsl:apply-templates select="Date" />
</td>
<td>
<xsl:apply-templates select="Amount" />
</td>
<td>
<xsl:variable name="running-total" select="sum(preceding-sibling::Payment/Amount) + Amount)" />
<xsl:value-of select="$running-total" />
</td>
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