|
next
|
Subject: Sum Groups into a subtotal and Grand Total Author: James Durning Date: 16 Nov 2006 11:45 AM
|
If you can use XSLT 2.0, you could use for-each-group.
<xsl:for-each-group select="/InvoiceStart/MetroGroupInvoicSummary" group-by="Header/InvoiceRecipient">
If you can only use XSLT 1.0, I recommend Muenchian grouping, http://www.jenitennison.com/xslt/grouping/muenchian.html.
1. Create a key at top:
<xsl:key name="InvoiceByRecipient" match="MetroGroupInvoicSummary" use="Header/InvoiceRecipient"/>
2. Get each group: In this case, we get the first element of each group.
<xsl:for-each select="/InvoiceStart/MetroGroupInvoicSummary[count(. | key('InvoiceByRecipient', Header/InvoiceRecipient)[1]) = 1]">
3. Sort by group, in this case use the Invoice Recipient.
<xsl:sort select="Header/InvoiceRecipient"/>
4. Sort by date? You might not have to if it is already sorted this way in your xml file.
<xsl:sort select="substring-after(substring-after(Header/Date, '.'), '.')"/>
<xsl:sort select="substring-after(Header/Date, '.')"/>
<xsl:sort select="Header/Date"/>
5. Output data for each.
<xsl:for-each select="key('InvoiceByRecipient', Header/InvoiceRecipient)"/>
...
6. Output group data:
<xsl:value-of select="sum(key('InvoiceByRecipient', Header/InvoiceRecipient)/InvoiceTotal/TotalNetAmount)
<xsl:value-of select="sum(key('InvoiceByRecipient', Header/InvoiceRecipient)/InvoiceTotal/VATAMT)
<xsl:value-of select="sum(key('InvoiceByRecipient', Header/InvoiceRecipient)/InvoiceTotal/TotalAmount)
I hope you can use some of this.
|
|
|