<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" encoding="UTF-8" indent="no"
              doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

  <xsl:template match="Root">
    <html>
      <head>
        <meta http-equiv="refresh" content="15" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><xsl:value-of select="Agent/Title"/></title>
        <link rel="stylesheet" type="text/css" href="../index.css"/>
      </head>
      
      <script type="text/JavaScript">        
        function getHost() 
        {
          url = window.location.hostname;
          document.getElementById("link").innerHTML= url + " Port 99";
          document.getElementById("link").href="telnet:" + url + ":99";
        }
      </script>
      <body onload="getHost()">
        <div id="base">
          <div id="title1"><xsl:value-of select="Agent/Title"/></div>
          <div id="bin">
            <table cellpadding="8" cellspacing="0">
              <tr>
                <td valign="top">
                  <xsl:if test="string(BinaryInSet/Entry)">
                    <table border="1" bordercolor="#ded2ee" cellpadding="3" cellspacing="0">
                      <tr class="th1"><td colspan="4">Dry Contact Inputs</td></tr>
                      <tr class="th2">
                        <td width="60">Name</td>
                        <td width="25">ID</td>
                        <td width="20">Current Value</td>
                        <td width="70">Alarm Alert</td>
                      </tr>
                      <xsl:for-each select="BinaryInSet/Entry">
                        <tr class="normal">
                          <td align="left"><xsl:value-of select="Name"/></td>
                          <td><xsl:value-of select="ID"/></td>
                          <td><xsl:value-of select="Value"/> 
                            <xsl:choose>
                              <xsl:when test="Value = 1">
                                (On)
                              </xsl:when>
                              <xsl:otherwise>
                                (Off)
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>
                          <td>
                            <xsl:choose>
                              <xsl:when test="Alarm = 0">
                                Active if on
                              </xsl:when>
                              <xsl:when test="Alarm = 1">
                                Active if off
                              </xsl:when>
                              <xsl:otherwise>
                                Disabled
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                  </xsl:if>
                </td>
                <td valign="top">
                  <xsl:if test="string(BinaryOutSet/Entry)">            
                    <table border="1" bordercolor="#ded2ee" cellpadding="3" cellspacing="0">
                      <tr class="th1"><td colspan="4">Relay Outputs</td></tr>
                      <tr class="th2">
                        <td width="60">Name</td>
                        <td width="25">ID</td>
                        <td width="20">Current Value</td>
                        <td width="70">Mode</td>
                      </tr>
                      <xsl:for-each select="BinaryOutSet/Entry">
                        <tr class="normal">
                          <td align="left"><xsl:value-of select="Name"/></td>
                          <td><xsl:value-of select="ID"/></td>
                          <td><xsl:value-of select="Value"/> 
                            <xsl:choose>
                              <xsl:when test="Value = 1">
                                (On)
                              </xsl:when>
                              <xsl:otherwise>
                                (Off)
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>
                          <td>
                            <xsl:choose>
                              <xsl:when test="Mode = 0">
                                Manual
                              </xsl:when>
                              <xsl:otherwise> <!--Mode = 1-->
                                On if any alarm
                              </xsl:otherwise>
                            </xsl:choose>
                          </td>
                        </tr>
                      </xsl:for-each>
                    </table>
                  </xsl:if>
                </td>
              </tr>
            </table>
          </div>
          <div id="temp">
            <table border="1" bordercolor="#ded2ee" cellpadding="3" cellspacing="0">
              <tr class="th1"><th colspan="6">Sensors</th></tr>
              <tr class="th2">
                <td width="120">Name</td>
                <td width="80">ID</td>
                <td width="120" colspan="2">Current Value</td>
                <td width="140">Safe Range</td>
                <td width="140">Alarm Alert</td>
              </tr>              
              <xsl:for-each select="SenSet/Entry">
                <tr>
                  <xsl:choose>
                    <xsl:when test="State = 0">
                      <xsl:attribute name="class">normal</xsl:attribute>
                    </xsl:when><xsl:when test="State = 1">
                      <xsl:attribute name="class">out</xsl:attribute>
                    </xsl:when>
                    <xsl:when test="State = 2">
                      <xsl:attribute name="class">alarm</xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise><!--State = 4-->
                      <xsl:attribute name="class">invalid</xsl:attribute>
                    </xsl:otherwise>
                  </xsl:choose>
                  <td align="left"><xsl:value-of select="Name"/></td>
                  <td><xsl:value-of select="ID"/></td>
                  <td align="right" width="70"><xsl:value-of select="Value"/></td>
                  <td align="left" width="50"> 
                    <xsl:choose>
                      <xsl:when test="Units = 'C'">
                        °<xsl:value-of select="Units"/>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="Units"/>
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                  <td><xsl:value-of select="Min"/> .. <xsl:value-of select="Max"/></td>
                  <td>
                    <xsl:choose>
                      <xsl:when test="SNMPTrap + EmailSMS = 0">
                        Disabled
                      </xsl:when>
                      <xsl:when test="SNMPTrap + 2*EmailSMS = 1">
                        SNMP trap
                      </xsl:when>
                      <xsl:when test="SNMPTrap + 2*EmailSMS = 2">
                        Email
                      </xsl:when>
                      <xsl:otherwise><!--SNMPTrap + 2*EmailSMS = 3-->
                        Email and SNMP trap
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
          </div>

          <div id="info">
            <table border="0" bordercolor="#ded2ee" cellpadding="3" cellspacing="0">
              <tr>
                <td>Device name:</td>
                <td><xsl:value-of select="Agent/DeviceName"/></td>
              </tr>
              <tr>
              <td>Web Configuration:</td>
                <td><a href="index2.htm">Flash Setup</a></td>
              </tr>
              <tr>
                <td>Terminal Configuration (TCP Setup):</td>
                <td>Connect with Telnet to <a id="link" href="#"></a></td>
              </tr>
              <tr>
                <td>Firmware:</td>
                <td>Version: <b><xsl:value-of select="Agent/Version"/></b> (<a href="upload">update</a>) / <a href="poseidon.mib">MIB</a> / <a href="values.xsd">XSD</a></td>
              </tr>
            </table>
          </div>
          <div id="footer">For more information try <a href="#"><xsl:attribute name="href"><xsl:value-of select="Agent/Contact"/></xsl:attribute><xsl:value-of select="Agent/Contact"/></a></div>
        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
