<?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">IP Destinations</xsl:param>
	<xsl:param name="delete"/>
	<xsl:param name="view"/>
	<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">ip_destinations.py</xsl:with-param>
					<xsl:with-param name="message" select="$message"/>
				</xsl:call-template>
				<div id="displayresults">
					<div id="row">
						<h1 class="display">IP Destinations</h1>
						<table>
							<tr>
								<td><div class="blacktab">Global Settings</div></td>
							</tr>
							<tr>
								<td>
									<table class="boxholder">
										<tr>
											<td style="width: 25%">
												IPA: <font style="color: #ffffff"><xsl:value-of select="/configuration/iptv/global_settings/base_dest_ip_addr"/></font>
											</td>
											<td style="width: 25%">
												Port: <font style="color: #ffffff"><xsl:value-of select="/configuration/iptv/global_settings/default_dest_port"/></font>
											</td>
											<td style="width: 25%">
												Src Port: <font style="color: #ffffff"><xsl:value-of select="/configuration/iptv/global_settings/default_src_port"/></font>
											</td>
											<td style="width: 25%">
												IP TTL: <font style="color: #ffffff"><xsl:value-of select="/configuration/iptv/global_settings/default_opt_ip_ttl"/></font>
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
						<table>
							<tr class="headerrow">
								<td class="destheadercell">Name</td>
								<td class="destheadercell">Destination</td>
								<td class="destheadercell">Type</td>
								<td class="destheadercell" style="text-align:right;">Action</td>
							</tr>
							<xsl:apply-templates/>
						</table>
					</div>
				</div>
			</body>
		</html>
		</xsl:template>
		<xsl:template match="iptv">
		<xsl:for-each select="iptv_destination">
		   <xsl:sort data-type="number" select="substring-before(dest_ip_addr,'.')"/>
           <xsl:sort data-type="number" select="substring-before(substring-after(dest_ip_addr,'.'),'.')"/>
           <xsl:sort data-type="number" select="substring-before(substring-after(substring-after(dest_ip_addr,'.'),'.'),'.')"/>
           <xsl:sort data-type="number" select="substring-after(substring-after(substring-after(dest_ip_addr,'.'),'.'),'.')"/>
           <xsl:sort data-type="number" select="dest_port"/>
		    <tr class="destrow">
			<td class="destcell">
			  <xsl:choose> 
				<xsl:when test="name = ''">
				<xsl:value-of select="dest_ip_addr" />:<xsl:value-of select="dest_port" />
				</xsl:when>
				<xsl:otherwise>	 
				<xsl:value-of select="name"/>	 
				</xsl:otherwise>
			    </xsl:choose> 
			</td>
			<td class="destcell"><xsl:value-of select="dest_ip_addr" />:<xsl:value-of select="dest_port" /></td>
			<td class="destcell">
				<xsl:choose> 
				<xsl:when test="count(programs/program_reference) = 0">
				None
				</xsl:when>
				<xsl:when test="count(programs/program_reference) = 1">
				SPTS
				</xsl:when>
				<xsl:otherwise>	 
				MPTS
				</xsl:otherwise>
			    </xsl:choose>
			</td>
			<td class="destcell" style="text-align:right;" >[ 
			<a>
            		<xsl:attribute name="HREF">destinationx.py?function=edit&amp;destipaddr=<xsl:value-of select="dest_ip_addr"/>&amp;destport=<xsl:value-of select="dest_port"/>
            		</xsl:attribute>
                	<xsl:text>View</xsl:text>
            		</a>
			<!--a href="destinationx.py?function=view&amp;index={position()}">View</a-->  
			 ]</td>
		    </tr>
		    <tr class="destrow">
		    <td colspan="4" style="color:black;background:black;height:1px;width:800px;"></td>
		    </tr>
		</xsl:for-each>
		</xsl:template>
		
		<xsl:template match="text()"></xsl:template>
    </xsl:stylesheet>
