As the title says: How do you calculate the sum of calculated values? Using the XML and XSLT below, I get a table like this:
How would I total the "Extended Price" column to get a total of $70.00?
Code:
Item | Quantity | Unit Cost | Extended Price
1 | 1 | $5.00 | $5.00
2 | 2 | $10.00 | $20.00
3 | 3 | $15.00 | $45.00
Total: ?????
How would I total the "Extended Price" column to get a total of $70.00?
XML:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<invoice>
<item>
<itemnumber>1</itemnumber>
<quantity>1</quantity>
<unitcost>5.00</unitcost>
</item>
<item>
<itemnumber>2</itemnumber>
<quantity>2</quantity>
<unitcost>10.00</unitcost>
</item>
<item>
<itemnumber>3</itemnumber>
<quantity>3</quantity>
<unitcost>15.00</unitcost>
</item>
</invoice>
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:template match="/">
<style>
table
{
border-collapse:collapse;
}
table,th,td
{
border:1px solid black;
}
</style>
<html>
<body>
<table>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Unit Cost</th>
<th>Extended Price</th>
</tr>
<xsl:for-each select="invoice/item">
<tr>
<td>
<xsl:value-of select="itemnumber"/>
</td>
<td>
<xsl:value-of select="quantity"/>
</td>
<td>
<xsl:value-of select="format-number(unitcost,'$#,##0.00')"/>
</td>
<td>
<xsl:value-of select="format-number(unitcost*quantity,'$#,##0.00')"/>
</td>
</tr>
</xsl:for-each>
<tr>
<td colspan="3">Total:</td>
<td>?????</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>