<?xml version="1.0"?>

<!-- Extract value of XML Elements -->

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

	<xsl:template match="/">
		<html>
		<head><title>Value of XML elements</title></head>
		<body>

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

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

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

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

	<xsl:template name="displayTable">
		<TABLE BORDER="1">
		<caption align="left"><B>value-of select= ... </B></caption>
		<TR>
		<TD><B> . </B></TD>
		<TD> <xsl:value-of select="." /> </TD>
		</TR><TR>
		<TD><B> / </B></TD>
		<TD> <xsl:value-of select="/" /> </TD>
		</TR><TR>
		<TD><B> addrbook </B></TD>
		<TD><xsl:value-of select="addrbook" /> </TD>
		</TR><TR>
		<TD><B> addrbook/entry </B></TD>
		<TD><xsl:value-of select="addrbook/entry" /> </TD>
		</TR><TR>
		<TD><B> addrbook/entry[1] </B></TD>
		<TD><xsl:value-of select="addrbook/entry[1]" /> </TD>
		</TR><TR>
		<TD><B> addrbook/entry[2] </B></TD>
		<TD><xsl:value-of select="addrbook/entry[2]" /> </TD>
		</TR><TR>
		<TD><B> addrbook/entry[last( )] </B></TD>
		<TD><xsl:value-of select="addrbook/entry[last()]" /> </TD>
		</TR><TR>
		<TD><B> addrbook/entry[last( )-1] </B></TD>
		<TD><xsl:value-of select="addrbook/entry[last()-1]" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/name </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/name" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/name/text( ) </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/name/text()" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/name/first </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/name/first" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/name/first/text( ) </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/name/first/text()" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address/text( ) </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/text()" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address/city </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/city" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address/zip </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/zip" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address/@country </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/@country" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address/@country/text( ) </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/@country/text()" /> --invalid --</TD>
		</TR><TR>
		<TD><B> /addrbook/entry[2]/comment( ) </B></TD>
		<TD><xsl:value-of select="/addrbook/entry[2]/comment()" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry[2]/name/last </B></TD>
		<TD><xsl:value-of select="/addrbook/entry[2]/name/last" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry[2]/name/last[2] </B></TD>
		<TD><xsl:value-of select="/addrbook/entry[2]/name/last[2]" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address/city[@state] </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/city[@state]" /> </TD>
		</TR><TR>
		<TD><B><nobr> /addrbook/entry/address/city[@state='FL'] </nobr></B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address/city[@state='FL']" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address[zip] </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address[zip]" /> </TD>
		</TR><TR>
		<TD><B> /addrbook/entry/address[zip='54321'] </B></TD>
		<TD><xsl:value-of select="/addrbook/entry/address[zip='54321']" /> </TD>
		</TR><TR>
		<TD><B><nobr> /addrbook/entry/name/last </nobr></B></TD>
		<TD><xsl:value-of select="/addrbook/entry/name/last" /> </TD>
		</TR><TR>
		<TD><B> count(/addrbook/entry/name/last) </B></TD>
		<TD><xsl:value-of select="count(/addrbook/entry/name/last)" /> </TD>
		</TR><TR>
		<TD><B><nobr> //last </nobr></B></TD>
		<TD><xsl:value-of select="//last" /> </TD>
		</TR><TR>
		<TD><B> count(//last) </B></TD>
		<TD><xsl:value-of select="count(//last)" /> </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> substring(/addrbook/entry, 1, 25)</B></TD>
		<TD><xsl:value-of select="substring(/addrbook/entry, 1, 25)" /> </TD>
		</TR><TR>
		<TD><B> substring-after(/addrbook/entry, '123')</B></TD>
		<TD><xsl:value-of select="substring-after(/addrbook/entry, '123')" /> </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:template name="displayXML">
		<H1>Extract value-of XML Elements</H1>
		<hr/>
		<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:stylesheet>