<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="html" version="4.0"
		doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"
		doctype-system="http://www.w3.org/TR/html4/strict.dtd"
		encoding="utf-8" indent="yes" />

	<xsl:template match="/">
		<html>
			<head>
				<title>The United States Government Manual</title>
				<meta http-equiv="Content-Type"
					content="text/html; charset=utf-8" />
				<style type="text/css">
					.body { margin-left:150px;margin-right:150px; }
					.para {
					display:block;margin-top:10px;margin-bottom:10px;clear:both;width:100%;
					}
					.Category {display:block; margin-top:50px; margin-bottom:50px;
					text-align:center; font-size:32pt;}
					.AgencyName {display:block;
					margin-top:50px; margin-bottom:50px;
					text-align:center;
					font-size:24pt;}
					.Heading
					{display:block;font-weight:bold;margin-top:10px;}
					.Header
					{display:block;font-weight:bold;font-size:14pt;margin-top:30px;}
					.ProgramName {display:block;font-weight:bold;font-size:14pt;}
					.image {
					display:block;width:100%;
					margin-top:-120px;
					margin-bottom:-150px;
					margin-left:-50px;
					position:relative;
					z-index:-1;
					}
					.Footer{display:block;font-size:10pt;}
					.Address{display:block;font-size:10pt;font-style:italic;}
				</style>
			</head>
			<body class="body">
				<center>
					<h1>The United States Government Manual</h1>
				</center>
				<xsl:apply-templates />
			</body>
		</html>
	</xsl:template>

	<!-- Tags being Ignored -->
	<xsl:template match="EntityType|accessId">
	</xsl:template>

	<xsl:template
		match="Category|AgencyName|Header|Heading|Footer|Address|ProgramName">
		<span>
			<xsl:attribute name="class">
	          <xsl:value-of select="name()" />                   
	        </xsl:attribute>
			<xsl:apply-templates />
		</span>
	</xsl:template>

	<xsl:template match="WebAddress">
		<xsl:variable name="webAddress">
			<xsl:value-of select="." />
		</xsl:variable>
		<span style="display:block;">
			<a target="_blank">
				<xsl:attribute name="href">
					<xsl:value-of select="$webAddress" />
				</xsl:attribute>
				<xsl:value-of select="$webAddress" />
			</a>
		</span>
	</xsl:template>

	<xsl:template match="Record">
		<span>
			<i>
				<xsl:apply-templates />
			</i>
		</span>
	</xsl:template>

	<xsl:template match="Paragraph|para">
		<span class="para">
			<xsl:apply-templates />
		</span>
	</xsl:template>

	<xsl:template match="ProgramAndActivities">
		<span>
			<br />
			<br />
			<xsl:apply-templates />
		</span>
	</xsl:template>

	<xsl:template match="LeaderShipTables/LeaderShipTable">
		<span style="display:block;margin-top:20px;">
			<TABLE style="margin-top:10px;width:50%;align:center;border:1">
				<TR style="display:table-row;">
					<TH
						style="colspan:2;text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="Header" />
					</TH>
				</TR>
				<TR style="display:table-row;">
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">Title</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">Name</TH>
				</TR>
				<xsl:for-each select="LeaderShipTableValues/Values">
					<TR style="display:table-row;">
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:value-of select="TitleColumnValue" />
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:variable name="ncValue"
								select="NameColumnValue" />
							<xsl:choose>
								<xsl:when test="contains($ncValue,', Acting')">
									<xsl:value-of
										select="substring-before($ncValue,' Acting')" />
									<i> Acting</i>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="NameColumnValue" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
					</TR>
				</xsl:for-each>
			</TABLE>
		</span>
		<span class="Footer">
			<xsl:value-of select="FooterDetails/Email" />
			<br />
			<xsl:value-of select="FooterDetails/Footer" />
			<br />
			<xsl:apply-templates select="FooterDetails/WebAddress" />
		</span>
	</xsl:template>

	<xsl:template
		match="Activity/KeyOfficialTables/KeyOfficialTable">
		<span style="display:block;">
			<TABLE style="margin-top:10px;align:center;border:1">
				<xsl:variable name="noOfColumns">
					<xsl:value-of
						select="KeyOfficialTableValues/Values[1]/NumberOfColumnVisible" />
				</xsl:variable>
				<xsl:attribute name="width">
				<xsl:value-of select="14*$noOfColumns" />%
			</xsl:attribute>
				<TR style="display:table-row;">
					<TH colspan="7"
						style="text-align:center;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="TableHeader" />
					</TH>
				</TR>
				<TR style="display:table-row;">
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnOneHeader" />
					</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnTwoHeader" />
					</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnThreeHeader" />
					</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnFourHeader" />
					</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnFiveHeader" />
					</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnSixHeader" />
					</TH>
					<TH
						style="text-align:left;display:table-cell;font-weight:bold;padding: 5px;">
						<xsl:value-of select="ColumnSevenHeader" />
					</TH>
				</TR>
				<xsl:for-each select="KeyOfficialTableValues/Values">
					<xsl:variable name="value1">
						<xsl:value-of select="ColumnOneValue" />
					</xsl:variable>
					<xsl:variable name="value2">
						<xsl:value-of select="ColumnTwoValue" />
					</xsl:variable>
					<xsl:variable name="value3">
						<xsl:value-of select="ColumnThreeValue" />
					</xsl:variable>
					<xsl:variable name="value4">
						<xsl:value-of select="ColumnFourValue" />
					</xsl:variable>
					<xsl:variable name="value5">
						<xsl:value-of select="ColumnFiveValue" />
					</xsl:variable>
					<xsl:variable name="value6">
						<xsl:value-of select="ColumnSixValue" />
					</xsl:variable>
					<xsl:variable name="value7">
						<xsl:value-of select="ColumnSevenValue" />
					</xsl:variable>
					<TR style="display:table-row;">
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value1,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value1" />
									</xsl:attribute>
										<xsl:value-of select="$value1" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value1" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value2,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value2" />
									</xsl:attribute>
										<xsl:value-of select="$value2" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value2" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value1,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value3" />
									</xsl:attribute>
										<xsl:value-of select="$value3" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value3" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value4,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value4" />
									</xsl:attribute>
										<xsl:value-of select="$value4" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value4" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value5,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value5" />
									</xsl:attribute>
										<xsl:value-of select="$value5" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value5" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value1,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value6" />
									</xsl:attribute>
										<xsl:value-of select="$value6" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value6" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
						<TD style="text-align:left;display:table-cell;padding: 5px;">
							<xsl:choose>
								<xsl:when test="starts-with($value1,'http://')">
									<a target="_blank">
										<xsl:attribute name="href">
										<xsl:value-of select="$value7" />
									</xsl:attribute>
										<xsl:value-of select="$value7" />
									</a>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$value7" />
								</xsl:otherwise>
							</xsl:choose>
						</TD>
					</TR>
				</xsl:for-each>
			</TABLE>
		</span>

		<span class="Footer">
			<xsl:value-of select="FooterDetails/Email" />
			<br />
			<xsl:value-of select="FooterDetails/Footer" />
			<br />
			<xsl:apply-templates select="FooterDetails/WebAddress" />
		</span> 
	</xsl:template>

	<xsl:template match="OrganizationChart">
		<xsl:variable name="orgChart">
			<xsl:value-of select="." />
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="contains($orgChart,'graphics/GOVMAN-')">
				<span class="image">
					<img>
						<xsl:attribute name="src">../graphics/<xsl:value-of
							select="substring-after($orgChart,'/')" /></xsl:attribute>
					</img>
				</span>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name="accessId">
					<xsl:value-of select="/GovernmentManual/accessId" />
				</xsl:variable>
				<xsl:if test="$orgChart!='' and $accessId!=''">
					<xsl:variable name="orgImage">
						../graphics/
						<xsl:value-of select="$accessId" />
						.jpg
					</xsl:variable>
					<span class="image">
						<img>
							<xsl:attribute name="src"><xsl:value-of
								select="$orgImage" /></xsl:attribute>
						</img>
					</span>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="apply-span">
		<span>
			<xsl:attribute name="class">
	        <xsl:value-of select="name()" /><xsl:text> </xsl:text><xsl:value-of
				select="name(parent::*)" />-<xsl:value-of
				select="name()" />        
	      </xsl:attribute>
			<xsl:apply-templates />
		</span>
	</xsl:template>

	<xsl:template
		match="SourceOfInformationDetails/EntitySourceOfInformation">
		<xsl:copy>
			<xsl:apply-templates select="Header" />
			<xsl:apply-templates select="Paragraph" />
			<xsl:apply-templates select="FooterDetails" />
		</xsl:copy>
	</xsl:template>

	<xsl:template
		match="ProgramAndActivities/ProgramAndActivity/Activity/Details/Detail">
		<xsl:copy>
			<xsl:apply-templates select="Header" />
			<xsl:apply-templates select="Paragraph" />
			<xsl:apply-templates select="FooterDetails" />
		</xsl:copy>
	</xsl:template>

</xsl:stylesheet>