<?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">Tables</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">tables.py</xsl:with-param>
					<xsl:with-param name="message" select="$message"/>
				</xsl:call-template>
				<div id="displayresults">
					<h1 class="display">Tables</h1>
					<xsl:apply-templates/>
				</div>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="configuration/egress/tables">
		<xsl:choose>
			<xsl:when test="@active = 'None'">
				<div class="row">
					<div class="generalcell">
						<b> Active Tables: </b>
					</div>
					<div class="generalcell">
						<xsl:value-of select="@active"/>
					</div>
				</div>
			</xsl:when>
			<xsl:when test="@active = 'MPEG'">
				<div class="row">
					<div class="generalcell">
						<b> Active Tables: </b>
					</div>
					<div class="generalcell">
						<xsl:value-of select="@active"/>
					</div>
				</div>
				<br/>
				<!--end of First Row -->
				<!-- MPEG Row -->
				<div class="row">
					<div class="largegeneralcell">
						<b>MPEG</b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PAT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pat/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PMT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pmt/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>CAT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/cat/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PAT Transport Stream ID: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pat/transport_stream_id"/>
					</div>
				</div>
			</xsl:when>
			<xsl:when test="@active = 'DVB'">
				<div class="row">
					<div class="generalcell">
						<b> Active Tables: </b>
					</div>
					<div class="generalcell">
						<xsl:value-of select="@active"/>
					</div>
				</div>
				<br/>
				<!--end of First Row -->
				<!-- MPEG Row -->
				<div class="row">
					<div class="largegeneralcell">
						<b>MPEG</b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PAT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pat/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PMT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pmt/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>CAT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/cat/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PAT Transport Stream ID: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pat/transport_stream_id"/>
					</div>
				</div>
				<br/>
				<!-- DVB Row -->
				<div class="row">
					<div class="largegeneralcell">
						<b>DVB</b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<img src="../images/trabuf.gif" WIDTH="20" HEIGHT="20"/>
						<br/>
						<b>
							Table Sharing
						</b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Enable: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="enableInterTables"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Master: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="enableInterMaster"/>
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<img src="../images/trabuf.gif" WIDTH="20" HEIGHT="20"/>
						<br/>
						<b>
							NIT
						</b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Enable: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/nit/enable"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/nit/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Network Name: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/nit/network_name"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Network ID: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/nit/network_id"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Original Network ID: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/nit/original_network_id"/>
					</div>
				</div>
				<xsl:for-each select="dvb/nit/transport_stream">
					<div style="/*height: auto;border:#889C9C solid 1px;*/">
						<!--xsl:if test="@index">
        				<div class="row">
    						<hr align="left" size="1" width="100"/>
            				<div class="generalcell">
                				<b>Index <xsl:value-of select="@index"/></b>
                    		</div>
            			</div>
            		</xsl:if>
        			<xsl:if test="@id">
        				<div class="row">
            				<div class="generalcell">
                				<b>Transport Stream ID: </b>
                    		</div>
                        	<div class="generalcell">
                            	<xsl:value-of select="@id"/>
        					</div>
            			</div>
            		</xsl:if>
        			<xsl:if test="@enable">
        				<div class="row">
            				<div class="generalcell">
                				<b>Enable: </b>
                    		</div>
                        	<div class="generalcell">
                            	<xsl:value-of select="@enable"/>
        					</div>
            			</div>
            		</xsl:if-->
						<xsl:if test="delivery_descriptor">
							<div class="row">
								<div class="subtablecell">
									<b>Delivery Descriptor: </b>
								</div>
								<div class="subtablecell">
									<xsl:value-of select="delivery_descriptor"/>
								</div>
							</div>
						</xsl:if>
						<!-- Cable and Satellite fields -->
						<xsl:if test="delivery_descriptor = 'Cable' or delivery_descriptor = 'Satellite'">
							<div class="row">
								<div class="subtablecell">
									<b>Frequency: </b>
								</div>
								<div class="subtablecell">
									<xsl:value-of select="frequency"/>
								</div>
							</div>
							<div class="row">
								<div class="subtablecell">
									<b>Symbol Rate: </b>
								</div>
								<div class="subtablecell">
									<xsl:value-of select="symbol_rate"/>
								</div>
							</div>
							<div class="row">
								<div class="subtablecell">
									<b>Modulation Type: </b>
								</div>
								<div class="subtablecell">
									<xsl:value-of select="modulation_type"/>
								</div>
							</div>
						</xsl:if>
						<!-- Satellite only fields -->
						<xsl:if test="delivery_descriptor = 'Satellite'">
							<xsl:if test="polarization">
								<div class="row">
									<div class="subtablecell">
										<b>Polarization: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="polarization"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="east_west">
								<div class="row">
									<div class="subtablecell">
										<b>East/West: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="east_west"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="orbital_position">
								<div class="row">
									<div class="subtablecell">
										<b>Orbital Position: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="orbital_position"/>
									</div>
								</div>
							</xsl:if>
						</xsl:if>
						<!-- Terrestrial only fields -->
						<xsl:if test="delivery_descriptor = 'Terrestrial'">
							<xsl:if test="center_frequency">
								<div class="row">
									<div class="subtablecell">
										<b>Center Frequency: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="center_frequency"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="bandwidth">
								<div class="row">
									<div class="subtablecell">
										<b>Bandwidth: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="bandwidth"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="constellation">
								<div class="row">
									<div class="subtablecell">
										<b>Constellation: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="constellation"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="hierarchy_information">
								<div class="row">
									<div class="subtablecell">
										<b>Hierarchy Information: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="hierarchy_information"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="code_rate_HP_stream">
								<div class="row">
									<div class="subtablecell">
										<b>Code Rate HP Stream: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="code_rate_HP_stream"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="code_rate_LP_stream">
								<div class="row">
									<div class="subtablecell">
										<b>Code Rate LP Stream: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="code_rate_LP_stream"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="guard_interval">
								<div class="row">
									<div class="subtablecell">
										<b>Guard Interval: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="guard_interval"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="transmission_mode">
								<div class="row">
									<div class="subtablecell">
										<b>Transmission Mode: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="transmission_mode"/>
									</div>
								</div>
							</xsl:if>
							<xsl:if test="other_frequency_flag">
								<div class="row">
									<div class="subtablecell">
										<b>Other Frequency Flag: </b>
									</div>
									<div class="subtablecell">
										<xsl:value-of select="other_frequency_flag"/>
									</div>
								</div>
							</xsl:if>
						</xsl:if>
						<!-- -->
					</div>
				</xsl:for-each>
				<!-- Test removed until application code updated for Chris' request-->
				<xsl:if test="not(contains($udd_info, 'cnf'))"><!-- and enableInterTables = enableInterMaster"-->
					<div class="row">
						<table class="outer">
							<tr>
								<td>
									User Definable First Loop Descriptors:
								</td>
							</tr>
							<tr>
								<td>
									<table class="inner">
										<tr>
											<th>
												Index
											</th>
											<th>
												Tag
											</th>
											<th>
												Data
											</th>
										</tr>
										<xsl:call-template name="udd">
											<xsl:with-param name="pText" select="$udd_info"/>
										</xsl:call-template>
									</table>
								</td>
							</tr>
						</table>
					</div>
				</xsl:if>
				<br/>
				<div class="row">
					<div class="tablecell">
						<img src="../images/trabuf.gif" WIDTH="20" HEIGHT="20"/>
						<br/>
						<b>
						 SDT
						</b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Enable: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/sdt/enable"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/sdt/rate"/> tenths
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="tablecell">
						<img src="../images/trabuf.gif" WIDTH="20" HEIGHT="20"/>
						<br/>
						<b> TDT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Enable: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/tdt/enable"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/tdt/rate"/> tenths
					</div>
				</div>
				<br/>
				<xsl:call-template name="time"/>
				<br/>
				<div class="row">
					<div class="tablecell">
						<img src="../images/trabuf.gif" WIDTH="20" HEIGHT="20"/>
						<br/>
						<b> EIT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Enable: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/eit/enable"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="dvb/eit/rate"/> tenths
					</div>
				</div>
				<br/>
				<!-- End DVB Row -->
			</xsl:when>
			<xsl:when test="@active = 'ATSC'">
				<div class="row">
					<div class="generalcell">
						<b> Active Tables: </b>
					</div>
					<div class="largegeneralcell">
						<xsl:value-of select="@active"/>
					</div>
				</div>
				<br/>
				<!--end of First Row -->
				<!-- MPEG Row -->
				<div class="row">
					<div class="largegeneralcell">
						<b>
							<b>MPEG</b>
							<hr align="left" size="1" width="300"/>
						</b>
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PAT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pat/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PMT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pmt/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>CAT Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/cat/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b>PAT Transport Stream ID: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="mpeg/pat/transport_stream_id"/>
					</div>
				</div>
				<br/>
				<!-- ATSC Row-->
				<div class="row">
					<div class="largegeneralcell">
						<b>
							<b>ATSC</b>
							<hr align="left" size="1" width="300"/>
						</b>
					</div>
				</div>
				<div class="row">
					<div class="tablecell">
						<b> PSIP </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Mode: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/table_mode"/>
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="tablecell">
						<b> VCT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/vct/rate"/> tenths
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Major Channel #: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/vct/major_channel"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Primary Language Code: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/vct/primary_language"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Secondary Language Code: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/vct/secondary_language"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Modulation Mode: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/vct/modulation_mode"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Carrier Frequency: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/vct/carrier_frequency"/>
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="tablecell">
						<b> MGT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/mgt/rate"/> tenths
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="tablecell">
						<b> STT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/stt/rate"/> tenths
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="tablecell">
						<b> RRT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/rrt/rate"/> tenths
					</div>
				</div>
				<br/>
				<div class="row">
					<div class="tablecell">
						<b> EIT </b>
						<hr align="left" size="1" width="300"/>
					</div>
				</div>
				<div class="row">
					<div class="subtablecell">
						<b>Rate: </b>
					</div>
					<div class="subtablecell">
						<xsl:value-of select="atsc/psip/eit/rate"/> tenths
					</div>
				</div>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template name ="time">
        <div class="row">
            <div class="subtablecell">
            	<img src="../images/trabuf.gif" WIDTH="20" HEIGHT="20"/>
				<br/>
            	<b>TOT</b>
            	<hr align="left" size="1" width="300"/>
            </div>
        </div>
        <div class="row">
            <div class="subtablecell">
                <b>Country Code: </b>
            </div>
            <div class="subtablecell">
					<xsl:value-of select="/configuration/egress/tables/dvb/tot/iso3166_country_code"/>
            </div>
        </div>
        <div class="row">
            <div class="subtablecell">
                <b>Country Time Zone: </b>
            </div>
            <div class="subtablecell">
					<xsl:value-of select="/configuration/egress/tables/dvb/tot/country_time_zone"/>
            </div>
        </div>
    </xsl:template>
	<xsl:template match="text()">
	</xsl:template>
	<xsl:template name="udd">
		<xsl:param name="pText" select="."/>
		<xsl:param name="index" select="0"/>
		<xsl:if test="string-length($pText)">
			<xsl:variable name="id" select="substring-before($pText, ',')"/>
			<xsl:variable name="data" select="substring-before(substring-after($pText, ','), ',')"/>
			<xsl:variable name="remainder" select="substring-after(substring-after($pText, ','), ',')"/>
			<tr style="font-weight: normal">
				<td>
					<xsl:value-of select="$index"/>
				</td>
				<td>
					<xsl:value-of select="$id"/>
				</td>
				<td>
					<xsl:value-of select="$data"/>
				</td>
			</tr>
			<xsl:call-template name="udd">
				<xsl:with-param name="pText" select="$remainder"/>
				<xsl:with-param name="index" select="$index + 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>
