<?xml version="1.0"?>

<!-- Example of Variables and Parameters -->

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

	<xsl:template match="/">
		<html>
		<head><title>Variables and Parameters</title></head>
		<body>
		<H1>Variables and Parameters</H1>
		<hr/>

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

		<BR /> <hr/>

		<H2> Parameters </H2>
		<xsl:apply-templates select="addrbook/entry" /> 
		
		</body>
		</html>
	</xsl:template>

	<!--================= Example of variables ===========================================-->

	<xsl:template name="displayTable">

		<!--================ Define the variable ==============================-->

                <xsl:variable name="num"> 5 </xsl:variable>
                <xsl:variable name="color">cyan</xsl:variable>
                <xsl:variable name="firstname" select="/addrbook/entry/name/first" />
                <xsl:variable name="fullname">
			<xsl:value-of select="/addrbook/entry/name" />
		</xsl:variable>
                <xsl:variable name="num2">
			<xsl:value-of select="($num + 3) * 2" />
		</xsl:variable>

		<TABLE BORDER="1">
		<TR>

		<!--============ Display the definintion of the variable ==============-->

		<TH colspan="2" bgcolor="lightyellow">-- Define Variables --</TH>
		</TR><TR>
		<TD colspan="2"><B> <xsl:variable name="num">5 </xsl:variable> </B></TD>
		</TR><TR>
		<TD colspan="2"><B> <xsl:variable name="color">cyan </xsl:variable> </B></TD>
		</TR><TR>
		<TD colspan="2"><B> <xsl:variable name="firstname" select="/addrbook/entry/name/first" /> </B></TD>
		</TR><TR>
		<TD colspan="2"><B> <xsl:variable name="fullname"> <xsl:value-of select="/addrbook/entry/name" /> </xsl:variable> </B></TD>
		</TR><TR>
		<TD colspan="2"><B> <xsl:variable name="num2"> <xsl:value-of select="($num + 3) * 2" /> </xsl:variable> </B></TD>
		</TR><TR>

		<!--============== Use the variables defined above ====================-->

		<TH colspan="2" bgcolor="lightyellow">--  Use the Variables --</TH>
		</TR><TR>
		<TD><B> <xsl:value-of select="$num" /> </B></TD>
		<TD><xsl:value-of select="$num" /> </TD>
		</TR><TR>
		<TD><B> <xsl:value-of select="$color" /> </B></TD>
		<TD><xsl:value-of select="$color" /> </TD>
		</TR><TR>
		<TD><B> <xsl:value-of select="$firstname" /> </B></TD>
		<TD><xsl:value-of select="$firstname" /> </TD>
		</TR><TR>
		<TD><B> <xsl:value-of select="$fullname" /> </B></TD>
		<TD><xsl:value-of select="$fullname" /> </TD>
		</TR><TR>
		<TD><B> <xsl:value-of select="$num2" /> </B></TD>
		<TD><xsl:value-of select="$num2" /> </TD>
		</TR><TR>
		<TD><B> <TD bgcolor="{$color}"> <xsl:value-of select="$fullname"/> <TD> </B></TD>
		<TD bgcolor="{$color}"> <xsl:value-of select="$fullname" /> </TD>
		</TR><TR>
		<TD><B> <xsl:if test="$color = 'cyan' "> Yes it is </xsl:if></B></TD>
		<TD><xsl:if test="$color = 'cyan'"> Yes it is </xsl:if> </TD>
		</TR><TR>
		<TD><B> <xsl:if test="contains($fullname, 'Sul')"> Yes it does </xsl:if></B></TD>
		<TD><xsl:if test="contains($fullname, 'Sul')"> Yes it does </xsl:if> </TD>
		</TR>
		</TABLE>
	</xsl:template>	

	<!--================= Example of Parameters ===========================================-->

	<xsl:template match="entry">

		<!--============ Pass parameters to address template ================-->

		<xsl:apply-templates select="address">
			<xsl:with-param name="color">tan</xsl:with-param> 
			<xsl:with-param name="city" select="address/city" />
		</xsl:apply-templates>
	</xsl:template>


	<xsl:template match="address">

		<!--============ Receive parameters =================================-->

		<xsl:param name="color"> white </xsl:param>
		<xsl:param name="city">--unknown--</xsl:param>

		<TABLE BORDER="1" WIDTH="600">
		<TR>

		<!--============ Display the passing parameters =====================-->

		<TH colspan="2" bgcolor="lightyellow">-- Send Parameters --</TH>
		</TR><TR>
		<TD colspan="2"><B> <xsl:with-param name="color">tan </xsl:with-param> </B></TD>
		</TR><TR>
		<TD colspan="2"><B> <xsl:with-param name="city" select="address/city" /> </B></TD>
		</TR><TR>
		<TH colspan="2" bgcolor="lightyellow">-- Receive Parameters --</TH>
		</TR><TR>
		<TD colspan="2"><B> <xsl:param name="color"> white </xsl:param> </B></TD>
		</TR><TR>
		<TD colspan="2"><B> <xsl:param name="city"> --unknown-- </xsl:param> </B></TD>
		</TR><TR>

		<!--============ Use the passed parameters ==========================-->

		<TH colspan="2" bgcolor="lightyellow">-- Use Parameters --</TH>
		</TR><TR>
		<TD><B> <xsl:value-of select="$color" /> </B></TD>
		<TD> <xsl:value-of select="$color" /> </TD>
		</TR><TR>
		<TD><B> <xsl:value-of select="$city" /> </B></TD>
		<TD><xsl:value-of select="$city" /> </TD>
		</TR><TR>
		<TD><B> <TD bgcolor="{$color}"> <xsl:value-of select="$city"/> <TD> </B></TD>
		<TD bgcolor="{$color}"> <xsl:value-of select="$city" /> </TD>
		</TR>
		</TABLE>
		<BR />
	</xsl:template>	

</xsl:stylesheet>