XML Vol 2 Issue 2 - pg.64
XSL 101: XSL Functionality, by Frank
Neugebauer
Listing 1
<?xml version="1.0"
encoding="UTF-8"?>
<INVOICE>
<ITEM>
<ID>S072796</ID>
<DESC>Item 1</DESC>
<PRICE>27.40</PRICE>
</ITEM>
<ITEM>
<ID>G051099</ID>
<DESC>Item 2</DESC>
<PRICE>243.33</PRICE>
</ITEM>
<ITEM>
<ID>K032669</ID>
<DESC>Item 3</DESC>
<PRICE>44.23</PRICE>
</ITEM>
</INVOICE>
Listing 2
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html">
<xsl:template match="/">
<HTML>
<BODY>
<!-- count -->
<H3>Total Items:
<xsl:value-of
select="count(//ITEM)"/>
</H3>
<!-- sum unformatted -->
<H3>Grand Total:
<xsl:value-of
select="sum(//PRICE)"/>
</H3>
<!-- format number -->
<H3>Grand Total Formatted:
<xsl:value-of
select="format-number(sum(//PRICE),
'$#,##0.00')"/>
</H3>
<!-- concat 1st ID and desc -->
<H3>First ID and Desc:
<xsl:value-of
select="concat(//ITEM[1]/ID,
//ITEM[1]/DESC)"/>
</H3>
</BODY>
</HTML>
</xsl:template>
</xsl:output>
</xsl:stylesheet>
Listing 3
<HTML>
<BODY>
<H3>Total Items: 3</H3>
<H3>Grand Total:
314.96000000000004</H3>
<H3>Grand Total Formatted:
$314.96</H3>
<H3>First ID and Desc:
S072796Item 1</H3>
</BODY>
</HTML>