<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
	<xsl:param name="message"/>
	<xsl:param name="pageTitle">Mappings</xsl:param>
	<xsl:include href="namedtemplates.xsl"/>
	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:value-of select="$web_title"/>
				</title>
				<xsl:call-template name="common_imports"/>
			</head>
			<body onload="window.defaultStatus=''; StartFloat();">
				<xsl:call-template name="initROPage">
					<xsl:with-param name="pageName">advmappings.py</xsl:with-param>
					<xsl:with-param name="message" select="$message"/>
				</xsl:call-template>
				<div id="displayresults">
					<h1 class="display">Mappings</h1>
					<table class="serviceTable" width="950px">
						<!--tr class="row">
							<td class="headerroutecell">Input</td>
							<td class="headerroutecell">Svc. ID In</td>
							<td class="headerroutecell">Svc. ID Out</td>
							<td class="headerroutecell">Scramble</td>
							<td class="headerroutecellname">Name</td>
						</tr-->
						<thead>
						<tr class="service">
							<th class="standard" style="width:90px;">Input</th>
							<th class="standard" style="width:90px;">Svc. ID In</th>
							<th class="standard" style="width:90px;">Svc. ID Out</th>
							<xsl:choose>
								<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
									<th class="standard" style="width:90px;">Major-Minor</th>
								</xsl:when>
								<xsl:otherwise>
									<th class="standard" width="90px">LCN</th>
								</xsl:otherwise>
							</xsl:choose>
							<th class="standard" style="width:90px;">Scramble</th>
							<xsl:choose>
								<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
									<th class="standard" width="90px">Short Name</th>
								</xsl:when>
								<xsl:otherwise>
									<th class="standard">Name</th>
								</xsl:otherwise>
							</xsl:choose>
							<xsl:choose>
								<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
									<th class="standard">Extended Name</th>
								</xsl:when>
								<xsl:otherwise>
									<th class="standard">Provider</th>
								</xsl:otherwise>
							</xsl:choose>
						</tr>
						</thead>
						<!--xsl:apply-templates/-->
						<!-- xsl:for-each select="configuration/port" -->
						<tbody>
							<xsl:call-template name="getRoutedPrograms">
								<xsl:with-param name="aPort" select="."/>
								<xsl:with-param name="aIndex" select="@index"/>
							</xsl:call-template>
						</tbody>
						<!-- /xsl:for-each -->
					</table>
				</div>
			</body>
		</html>
	</xsl:template>
	<xsl:template name="getRoutedPrograms">
		<xsl:param name="aPort"/>
		<xsl:param name="aIndex"/>
		<xsl:for-each select="/configuration/status/port/routed_programs/program | /configuration/status/ghost/program">
		<!--xsl:for-each select="/configuration/status/port[@index=$aIndex]/routed_programs/program"-->
	        <xsl:sort select="./@assigned" data-type="number" order="ascending"/>
			<xsl:variable name="aPort" select="../.."/>
			<xsl:variable name="aIndex" select="../../@index"/>
			<xsl:variable name="programNumber" select="@program_number_in"/>
			<xsl:variable name="status" select="@status"/>
			<xsl:variable name="assigned" select="/configuration/status/port[@index=$aIndex]/routed_programs/program[@program_number_in=$programNumber]/@assigned"/>
			<tr>
				<xsl:choose>
			    	<xsl:when test="$status='active'">
						<xsl:attribute name="class">activeService</xsl:attribute>
				   </xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="class">inactiveService</xsl:attribute>
				</xsl:otherwise>
				</xsl:choose>
				<td>
					<xsl:value-of select="$aPort/@index"/>
				</td>
				<td>
					<!--xsl:value-of select="/configuration/status/port[@index=$aIndex]/routed_programs/program[@program_number_in=$programNumber]/"/-->
					<xsl:value-of select="$programNumber"/>
				</td>
				<td>
					<xsl:value-of select="$assigned"/>
					<!--xsl:value-of select="/configuration/status/port[@index=$aIndex]/routed_programs/program[@program_number_in=$programNumber]/@assigned"/-->
				</td>
				<td>
					<xsl:choose>
						<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
							<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$programNumber]/program_tables/atsc/vct/major_channel"/>
							<xsl:text>-</xsl:text>
							<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$programNumber]/program_tables/atsc/vct/minor_channel"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$programNumber]/logical_channel_num"/>
						</xsl:otherwise>
					</xsl:choose>
				</td>
				<td>
					<xsl:text>No</xsl:text>
				</td>
				<td>
					<xsl:value-of select="/configuration/status/port[@index=$aIndex]/routed_programs/program[@program_number_in=$programNumber]/name_out"/>
				</td>
				<td>
					<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$programNumber]/provider_out"/>
				</td>
			</tr>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="getRoutedGhostPrograms">
		<xsl:param name="aGhost"/>
		<xsl:param name="aIndex"/>
		<xsl:for-each select="/configuration/status/ghost[@index=$aIndex]/program">
			<xsl:variable name="programNumber" select="@program_number_in"/>
			<tr class="row">
				<td class="routecell">
					<xsl:value-of select="$aGhost/@index"/>
				</td>
				<td class="routecell">
					<xsl:value-of select="/configuration/status/ghost[@index=$aIndex]/program/@assigned"/>
				</td>
				<td class="routecell">
					<xsl:choose>
						<xsl:when test="$aGhost/program/ca/scramble">
							<xsl:value-of select="$aGhost/program/scramble"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>No</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</td>
				<td class="routecell">
					<xsl:value-of select="/configuration/status/ghost[@index=$aIndex]/program/name_out"/>
				</td>
			</tr>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="text()">
	</xsl:template>
</xsl:stylesheet>
