<?xml version="1.0"?>

<!-- Various XSLT functions -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

	<xsl:template match="/">
		<html>
		<head><title>XSLT functions</title></head>
		<body>
		<H1>Various XSLT functions</H1>
		<hr/>

		<xsl:call-template name="displayXML" />
		<xsl:call-template name="displayTable" />

		</body>
		</html>
	</xsl:template>

	<!--======================================================================-->
	<xsl:template name="displayXML">
		<font color="navy">
		<pre>
		<addrbook>
    		    <entry>
			<!-- first entry -->
			<name>
			    <first>Sam</first>
			    <last>Sultan</last>
			</name>
			<address country="US">123 Main street
			    <city state="NY">New York</city>
			    <zip>12345</zip>
			</address>
    		    </entry>
    		    <entry>
			<!-- second entry -->
			<name>
			    <first>Donald</first>
			    <last type="normal">Duck</last>
			    <last type="aka">Quack</last>
			</name>
			<address country="US">1 Magic Kingdom Drive
			    <city state="FL">Orlando</city>
			    <zip>54321</zip>
			</address>
    		    </entry>
		</addrbook>
		</pre>
		</font>
	</xsl:template>	

	<!--======================================================================-->

	<xsl:template name="displayTable">
		<TABLE BORDER="1">
                <TR>
		<TD><B> count(/addrbook/entry) </B></TD>
		<TD><xsl:value-of select="count(/addrbook/entry)" /> </TD>
		</TR><TR>
		<TD><B> sum(/addrbook/entry/address/zip) </B></TD>
		<TD><xsl:value-of select="sum(/addrbook/entry/address/zip)" /> </TD>
		</TR><TR>
		<TD><B> sum(/addrbook/entry/address/zip) div 2</B></TD>
		<TD><xsl:value-of select="sum(/addrbook/entry/address/zip) div 2" /> </TD>
		</TR><TR>
		<TD><B> sum(/addrbook/entry/address/zip) * count(/addrbook/entry)</B></TD>
		<TD><xsl:value-of select="sum(/addrbook/entry/address/zip) * count(/addrbook/entry)" /> </TD>
		</TR><TR>
		<TD><B> substring(/addrbook/entry, 1, 25)</B></TD>
		<TD><xsl:value-of select="substring(/addrbook/entry, 1, 25)" /> </TD>
		</TR><TR>
		<TD><B> contains(addrbook/entry, 'New York')</B></TD>
		<TD><xsl:value-of select="contains(addrbook/entry, 'New York')" /> </TD>
     		</TR>
		</TABLE>
	</xsl:template>	

</xsl:stylesheet>