<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:variable name="company1" select="document('AFDContractFurniture.xml')" />
	<xsl:variable name="company2" select="document('beckmanInn.xml')" />
	<xsl:variable name="company3" select="document('SecretService.xml')" />
	<xsl:variable name="company4" select="document('USPS.xml')" />
	<xsl:template match="/">
		<html>
			<head>
				<title>Lab puppy 4</title>
			</head>
			<body>
				<h4>Lab Puppy #4 - Part 1</h4>
				<xsl:call-template name="part1" />
				<br />
				<hr />
				<h4>Lab Puppy #4 - Part 2</h4>
				<xsl:call-template name="part2" />
			</body>
		</html>
	</xsl:template>
	<!--PART 1-->
	<xsl:template name="part1">
		<p>
		Zip codes &lt; 55555 in <font color="blue">blue</font>, Zip codes &gt; 55555 in <font color="red">red</font> 
		</p>
		<table width="450">
			<tr>
				<td>
					<b>Name</b>
				</td>
				<td>
					<b>Zip code</b>
				</td>
			</tr>
			<tr>
				<td>
					<xsl:value-of select="$company4//name" />
					<br />
					<xsl:value-of select="$company1//name" />
					<br />
					<xsl:value-of select="$company2//name" />
					<br />
				</td>
				<td>
					<xsl:call-template name="zipColor">
						<xsl:with-param name="zipcode" select="$company4//addressLine[5]" />
					</xsl:call-template>
					<br />
					<xsl:call-template name="zipColor">
						<xsl:with-param name="zipcode" select="$company1//addressLine[5]" />
					</xsl:call-template>
					<br />
					<xsl:call-template name="zipColor">
						<xsl:with-param name="zipcode" select="substring($company2//address[@useType = 'Main']/addressLine[2], 16)" />
					</xsl:call-template>
				</td>
			</tr>
		</table>
	</xsl:template>
	<!-- PART 2 -->
	<xsl:template name="part2">
		<xsl:variable name="USSS" select="$company3//name" />
		<xsl:variable name="USPS" select="$company4//name" />
		<h3>Government Agrencies</h3>
		<h3>
			<xsl:value-of select="$USSS" />
		</h3>
		<table width="100%">
			<xsl:for-each select="$company3//categoryBag/keyedReference">
				<tr>
					<td width="200">
						<xsl:value-of select="@keyValue" />
					</td>
					<td width="100">
						<xsl:value-of select="ancestor::*//businessService[1]/name" />
					</td>
					<td width="100">
						<xsl:value-of select="ancestor::*//businessService[1]//bindingTemplate/description" />
					</td>
					<td width="200">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="ancestor::*//businessService[1]//bindingTemplate/accessPoint" />
							</xsl:attribute>
							<xsl:value-of select="$USSS" />
						</a>
					</td>
				</tr>
			</xsl:for-each>
		</table>
		<br />
		<h3>
			<xsl:value-of select="$USPS" />
		</h3>
		<table width="100%">
			<xsl:for-each select="$company4//categoryBag/keyedReference">
				<tr>
					<td width="200">
						<xsl:value-of select="@keyValue" />
					</td>
					<td width="100">
						<xsl:value-of select="ancestor::*//businessService[1]/name" />
					</td>
					<td width="100">
						<xsl:value-of select="ancestor::*//businessService[1]//bindingTemplate/description" />
					</td>
					<td width="200">
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="ancestor::*//businessService[1]//bindingTemplate/accessPoint" />
							</xsl:attribute>
							<xsl:value-of select="substring($USPS, 1, 28)" />
						</a>
					</td>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>
	<!-- Determines the color of the zipcodes -->
	<xsl:template name="zipColor">
		<xsl:param name="zipcode" />
		<xsl:choose>
			<xsl:when test="$zipcode &lt; 55555">
				<font color="blue">
					<xsl:value-of select="$zipcode" />
				</font>
			</xsl:when>
			<xsl:otherwise>
				<font color="red">
					<xsl:value-of select="$zipcode" />
				</font>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

