I have following source XML
Source XML
<?xml version="1.0" encoding="UTF-16"?>
<PropertySet><SiebelMessage><ListOfXRX_spcUSCO_spcCOL_spcInvoice_spcAR_spcSummary>
<FS_spcInvoice
Type_spcCode="20"
XCS_spcINQ_spcPO_spcNumber="7500020052"
XCS_spcINQ_spcSerial_spcNumber="VDR551061"
XCS_spcINQ_spcCustomer_spcNumber="712246305"
XCS_spcINQ_spcInvoice_spcNumber="060853967"
Gross_spcAmount="747.06"
Invoice_spcDate="04/01/2012"></FS_spcInvoice>
<FS_spcInvoice
Type_spcCode="20"
XCS_spcINQ_spcPO_spcNumber="7500020052"
XCS_spcINQ_spcSerial_spcNumber="VDR551061"
XCS_spcINQ_spcCustomer_spcNumber="712346305"
XCS_spcINQ_spcInvoice_spcNumber="063853967"
Gross_spcAmount="947.06"
Invoice_spcDate="04/01/2013"></FS_spcInvoice>
</ListOfXRX_spcUSCO_spcCOL_spcInvoice_spcAR_spcSummary></SiebelMessage></PropertySet>
I need to generate sorted list of invoices in HTML format. I am able to do that with help following XSLT
XSLT
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/" >
<html><head></head><body>
<H3>Summary</H3>
<table>
<thead>
<tr><th>Invoice Number</th><th>Customer Number</th><th>Serial Number</th><th>PO Number</th><th>Invoice Date</th><th>Invoice Amount</th></tr>
</thead><tbody>
<xsl:apply-templates select="PropertySet/SiebelMessage/ListOfXRX_spcUSCO_spcCOL_spcInvoice_spcAR_spcSummary/FS_spcInvoice">
<xsl:sort select="@Gross_spcAmount" order="descending" />
</xsl:apply-templates>
<tr><td colspan="5">Total Amount</td><td></td></tr>
</tbody></table></body></html>
</xsl:template>
<xsl:template match='FS_spcInvoice'>
<tr>
<td><xsl:value-of select="@XCS_spcINQ_spcInvoice_spcNumber" /></td>
<td><xsl:value-of select="@XCS_spcINQ_spcCustomer_spcNumber" /></td>
<td><xsl:value-of select="@XCS_spcINQ_spcSerial_spcNumber" /></td>
<td><xsl:value-of select="@XCS_spcINQ_spcPO_spcNumber" /></td>
<td><xsl:value-of select="@Invoice_spcDate" /></td>
<td><xsl:value-of select="@Gross_spcAmount" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>
I have two questions
1. How to SUM?
I need to display sum of all invoices in the last row of the table. I have an idea that I need to use nodeset but I am not able to figure out how?
2. Dynamic Sort
Is it possible to provide element name or attribute name dynamically to xsl:sort.
For example the attribute name on which to sort is provided as different element value.
<sortby>Gross_spcAmount</sortby>