<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" media-type="text/html"  indent="yes" encoding="utf-8"/>
  <xsl:param name="APP_ROOT" select="'http://localhost:8080/SigmaSure'"/>
  <xsl:param name="UNIT_REPORT_ID" select="'1'"/>
  <xsl:template match="/">
    <html>
      <head>
      <!-- Put css stuff here -->
        <style>
          .TableHeader {
          font-family: Arial;
          font-size: 12px;
          border-top-style: solid;
          border-right-style: solid;
          border-bottom-style: solid;
          border-left-style: solid;
          border-top-width: thin;
          border-right-width: thin;
          border-bottom-width: thin;
          border-left-width: thin;
          border-top-color: #000000;
          border-right-color: #000000;
          border-bottom-color: #000000;
          border-left-color: #000000;
          text-align: center;
          height: 30px;
          color: #000000;
          font-weight: 900;
          }
          .TableHeaderL {
          font-family: Arial;
          font-size: 12px;
          border-top-style: solid;
          border-right-style: solid;
          border-bottom-style: solid;
          border-left-style: solid;
          border-top-width: thin;
          border-right-width: thin;
          border-bottom-width: thin;
          border-left-width: thin;
          border-top-color: #000000;
          border-right-color: #000000;
          border-bottom-color: #000000;
          border-left-color: #000000;
          text-align: left;
          height: 30px;
          color: #000000;
          font-weight: 900;
          }
          .TableHeaderC {
          font-family: Arial;
          font-size: 12px;
          border-top-style: solid;
          border-right-style: solid;
          border-bottom-style: solid;
          border-left-style: solid;
          border-top-width: thin;
          border-right-width: thin;
          border-bottom-width: thin;
          border-left-width: thin;
          border-top-color: #000000;
          border-right-color: #000000;
          border-bottom-color: #000000;
          border-left-color: #000000;
          text-align: center;
          height: 30px;
          color: #000000;
          font-weight: 900;
          }
          h1 {
          text-align:center;
          font-size:18pt;
          }
          h2 {
          font-family:Arial;
          font-weight:400;
          font-size:12pt;
          }
          h5	{
          font-family: Arial;
          font-size: 24pt;
          border-style: solid;
          font-weight: normal;
          text-align: left;
          border-width: thin;
          vertical-align: top;
          }
          h6 {
          border-style: none;
          border-width: thin;
          border-color: #000000;
          text-align: left;
          font-family: Arial;
          font-size: 18pt;
          font-weight: bold;
          }
          .ItemName {
          font-family: Arial;
          font-size: 10pt;
          font-weight: bold;
          }
          .SubItemName {
          font-family: Arial;
          font-size: 10pt;
          font-weight: normal;
          }
          .outCome {
          font-family: Arial;
          font-size: 10pt;
          border-top-style: none;
          border-right-style: none;
          border-bottom-style: none;
          border-left-style: none;
          border-top-width: thin;
          border-right-width: thin;
          border-bottom-width: thin;
          border-left-width: thin;
          border-top-color: #000000;
          border-right-color: #000000;
          border-bottom-color: #000000;
          border-left-color: #000000;
          text-align: right;
          }
          .suboutCome{
          font-family: Arial;
          font-size: 10pt;
          border-top-style: none;
          border-right-style: none;
          border-bottom-style: none;
          border-left-style: none;
          border-top-width: thin;
          border-right-width: thin;
          border-bottom-width: thin;
          border-left-width: thin;
          border-top-color: #000000;
          border-right-color: #000000;
          border-bottom-color: #000000;
          border-left-color: #000000;
          text-align: center;
          }
        </style>
      </head>
      <body>
        <h1>Waters Corporation - Test Record</h1>
        <table border="3" width="100%">
          <td>
            <table border="0" width="100%" colspan="4">
              <tr>
                <td colspan="4">
                  <h2>
                    Part Number: <U>
                      <xsl:value-of select="/UnitReport/Category/Product/@part-no"/>
                    </U>
                  </h2>
                </td>
                <td>
                  <h2>
                    Product: <U>
                      <xsl:value-of select="/UnitReport/Category/Product/@name"/>
                    </U>
                  </h2>
                </td>
              </tr>
              <tr>
                <td colspan="4">
                  <h2>
                    Operator: <U>
                      <xsl:value-of select="/UnitReport/Operator/@name"/>
                    </U>
                  </h2>
                </td>
                <td>
                  <h2>
                    Start Time:
                    <U>
                      <xsl:variable name="start-time" select="/UnitReport/@start-time"></xsl:variable>
                      <xsl:value-of select="substring-before(substring-after($start-time,'-'),'-')"/>
                      <xsl:text>/</xsl:text>
                      <xsl:value-of select="substring-before(substring-after(substring-after($start-time,'-'),'-'),'T')"/>
                      <xsl:text>/</xsl:text>
                      <xsl:value-of select="substring-before($start-time,'-')"/>
                      <xsl:text>, </xsl:text>
                      <xsl:value-of select="substring-before(substring-after($start-time,'T'),':')"/>
                      <xsl:text>:</xsl:text>
                      <xsl:value-of select="substring-before(substring-after(substring-after($start-time,'T'),':'),':')"/>
                      <xsl:text>:</xsl:text>
                      <xsl:value-of select="substring-before(substring-after(substring-after(substring-after($start-time,'T'),':'),':'),'-')"/>
                    </U>
                  </h2>
                </td>
              </tr>
              <tr>
                <td colspan="4">
                  <h2>
                    Serial Number: <U>
                      <xsl:value-of select="/UnitReport/Category/Product/@serial-no"/>
                    </U>
                  </h2>
                </td>
                <td>
                  <h2>
                    End Time:
                    <U>
                      <xsl:variable name="end-time" select="/UnitReport/@end-time"></xsl:variable>
                      <xsl:value-of select="substring-before(substring-after($end-time,'-'),'-')"/>
                      <xsl:text>/</xsl:text>
                      <xsl:value-of select="substring-before(substring-after(substring-after($end-time,'-'),'-'),'T')"/>
                      <xsl:text>/</xsl:text>
                      <xsl:value-of select="substring-before($end-time,'-')"/>
                      <xsl:text>, </xsl:text>
                      <xsl:value-of select="substring-before(substring-after($end-time,'T'),':')"/>
                      <xsl:text>:</xsl:text>
                      <xsl:value-of select="substring-before(substring-after(substring-after($end-time,'T'),':'),':')"/>
                      <xsl:text>:</xsl:text>
                      <xsl:value-of select="substring-before(substring-after(substring-after(substring-after($end-time,'T'),':'),':'),'-')"/>
                    </U>
                  </h2>
                </td>
              </tr>
              <tr>
                <td colspan="4">
                  <h2>
                    Test System: <U>
                      <xsl:value-of select="/UnitReport/Station/@name"/>
                      <!-- <xsl:if test="string-length(/UnitReport/Station/@version)>0">
                        HW Ver. 
                        <xsl:value-of select="/UnitReport/Station/@version"/>
                      </xsl:if> -->
                    </U>
                  </h2>
                </td>
                <!--Factory Order -->
                <xsl:for-each select="UnitReport/Category/Product/Property/descendant::*">
                  <xsl:if test="(@name='Order')">
                    <td>
                      <h2>
                        <xsl:value-of select="@name"/>:
                        <U>
                          <xsl:variable name="FO" select="."/>
                          <xsl:choose>
                            <xsl:when test="string-length($FO)>0">
                              <xsl:value-of select="."/>
                            </xsl:when>
                            <xsl:otherwise>
                              N/A
                            </xsl:otherwise>
                          </xsl:choose>
                        </U>
                      </h2>
                    </td>
                  </xsl:if>
                </xsl:for-each>
              </tr>
              
              
              <!-- Test Software-->
              <xsl:for-each select="UnitReport/Station/Property/descendant::*">
                <xsl:if test="(@name='Test Software')">
                  <td colspan="4">
                    <h2>
                      <xsl:value-of select="@name"/>:
                      <U>
                        <xsl:variable name="TSW" select="."/>
                        <xsl:choose>
                          <xsl:when test="string-length($TSW)>0">
                            <xsl:value-of select="."/>
                          </xsl:when>
                          <xsl:otherwise>
                            N/A
                          </xsl:otherwise>
                        </xsl:choose>
                      </U>
                    </h2>
                  </td>
                </xsl:if>
              </xsl:for-each>
              
              
              <!-- Location -->
              <xsl:for-each select="UnitReport/Station/Property/descendant::*">
                <xsl:if test="(@name='Location')">
                  <td>
                    <h2>
                      <xsl:value-of select="@name"/>:
                      <U>
                        <xsl:variable name="LOC" select="."/>
                        <xsl:choose>
                          <xsl:when test="string-length($LOC)>0">
                            <xsl:value-of select="."/>
                          </xsl:when>
                          <xsl:otherwise>
                            N/A
                          </xsl:otherwise>
                        </xsl:choose>
                      </U>
                    </h2>
                  </td>
                </xsl:if>
              </xsl:for-each>
            </table>
          </td>
        </table>

        <xsl:for-each select="UnitReport/Category/Product/Property/descendant::*">
          <xsl:if test="(@name='TMD')">
                  <xsl:value-of select="@name"/>:
                  <xsl:variable name="TMD" select="."/>
                  <xsl:choose>
                    <xsl:when test="string-length($TMD)>0">
                      <xsl:value-of select="."/>
                      <tr>
                        <td>
                          <br></br>
                        </td>
                      </tr>
                    </xsl:when>
                    <xsl:otherwise>
                      N/A
                    </xsl:otherwise>
                  </xsl:choose>
          </xsl:if>
        </xsl:for-each>
        
        <xsl:for-each select="UnitReport/Category/Product/Property/descendant::*">
          <xsl:if test="(@name='Firmware')">
                  <xsl:value-of select="@name"/>:
                  <xsl:variable name="FW" select="."/>
                  <xsl:choose>
                    <xsl:when test="string-length($FW)>0">
                      <xsl:value-of select="."/>
                    </xsl:when>
                    <xsl:otherwise>
                      N/A
                    </xsl:otherwise>
                  </xsl:choose>
          </xsl:if>
        </xsl:for-each>
        
          <!-- TEST RUNS -->        
        
          <table cellspacing="0" width="100%" class="table" border="0">
             <!-- Table header -->
             <tr align="left">
               <td class="TableHeaderL">Name</td>
               <td class="TableHeaderC">LSL</td>
               <td class="TableHeaderC">Measurement</td>
               <td class="TableHeaderC">USL</td>
               <td class="TableHeaderC">Unit</td>
               <td class="TableHeaderC">&#160;&#160;&#160;&#160;Outcome&#160;&#160;&#160;&#160;</td>
             </tr>
          <xsl:for-each select="UnitReport/TestRun/*">
            <xsl:choose>
              <!-- Don't show failed Noise and Drift Tests-->
              <xsl:when test="(@name='Noise' or @name='Drift')"/>  
              <!-- Don't show tests we want to omit-->
              <xsl:when test="node()='Omit'"/>
           <xsl:otherwise>
            <tr>
            <xsl:choose>
              <xsl:when test="node()=Result or not(node())">
                <!--This is Bold Upper Level Test Run-->
                <!-- Test Name  -->
                <xsl:if test="string-length(./Result/Property/ValueDouble/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/Property/ValueDouble/@name"/>
                  </td>
                </xsl:if>
                <xsl:if test="string-length(./Result/ValueDouble/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/ValueDouble/@name"/>
                  </td>
                </xsl:if>
                <xsl:if test="string-length(./Result/Property/ValueString/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/Property/ValueString/@name"/>
                  </td>
                </xsl:if>
                <xsl:if test="string-length(./Result/ValueString/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/ValueString/@name"/>
                  </td>
                </xsl:if>
                <xsl:if test="string-length(./Result/Property/ValueBoolean/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/Property/ValueBoolean/@name"/>
                  </td>
                </xsl:if>
                <xsl:if test="string-length(./Result/ValueBoolean/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/ValueBoolean/@name"/>
                  </td>
                </xsl:if>

                <xsl:if test="string-length(./Result/Property/ValueInteger/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/Property/ValueInteger/@name"/>
                  </td>
                </xsl:if>

                <xsl:if test="string-length(./Result/ValueInteger/@name)>0">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="./Result/ValueInteger/@name"/>
                  </td>
                </xsl:if>
                
                <!-- Test has no reults -->
                <xsl:if test="not(node())">
                  <td class="ItemName" align="left">
                    <xsl:value-of select="@name"/>
                  </td>
                </xsl:if>
                <!-- LSL -->
                <xsl:choose>
                  <xsl:when test="string-length(./Result/Property/ValueDouble/@lsl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/Property/ValueDouble/@lsl"/>
                    </td>
                  </xsl:when>

                  <xsl:when test="string-length(./Result/ValueDouble/@lsl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/ValueDouble/@lsl"/>
                    </td>
                  </xsl:when>

                  <xsl:when test="string-length(./Result/Property/ValueInteger/@lsl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/Property/ValueInteger/@lsl"/>
                    </td>
                  </xsl:when>

                  <xsl:when test="string-length(./Result/ValueInteger/@lsl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/ValueInteger/@lsl"/>
                    </td>
                  </xsl:when>
                  
                  <xsl:otherwise>
                    <td></td>
                  </xsl:otherwise>
                </xsl:choose>
                <!-- Meas -->
                <xsl:if test="string-length(node()[1])>0">
                  <td class="ItemName" align="center">
                    <xsl:value-of select="node()[1]"/>
                  </td>
                </xsl:if>
                <xsl:if test="string-length(node()[1])=0">
                  <td></td>
                </xsl:if>
                <!-- USL  -->
                <xsl:choose>
                  <xsl:when test="string-length(./Result/Property/ValueDouble/@usl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/Property/ValueDouble/@usl"/>
                    </td>
                  </xsl:when>
                  <xsl:when test="string-length(./Result/ValueDouble/@usl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/ValueDouble/@usl"/>
                    </td>
                  </xsl:when>
                  <xsl:when test="string-length(./Result/Property/ValueInteger/@usl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/Property/ValueInteger/@usl"/>
                    </td>
                  </xsl:when>
                  <xsl:when test="string-length(./Result/ValueInteger/@usl)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/ValueInteger/@usl"/>
                    </td>
                  </xsl:when>
               <xsl:otherwise>
                    <td></td>
                  </xsl:otherwise>
                </xsl:choose>
                <!-- UOM  -->
                <xsl:choose>
                  <xsl:when test="string-length(./Result/Property/ValueDouble/@uom)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/Property/ValueDouble/@uom"/>
                    </td>
                  </xsl:when>
                  <xsl:when test="string-length(./Result/ValueDouble/@uom)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/ValueDouble/@uom"/>
                    </td>
                  </xsl:when>
                  <xsl:when test="string-length(./Result/Property/ValueInteger/@uom)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/Property/ValueInteger/@uom"/>
                    </td>
                  </xsl:when>
                  <xsl:when test="string-length(./Result/ValueInteger/@uom)>0">
                    <td class="ItemName" align="center">
                      <xsl:value-of select="./Result/ValueInteger/@uom"/>
                    </td>
                  </xsl:when>
               <xsl:otherwise>
                    <td></td>
                  </xsl:otherwise>
                </xsl:choose>
                <!-- Grade  -->
                <xsl:if test="string-length(./@grade)>0">
                  <td class="ItemName" align="center">
                    <xsl:value-of select="./@grade"/>
                  </td>
                </xsl:if>
              </xsl:when>  <!-- when uppper level test-->
             <xsl:otherwise>
                <!--This is sub test with name and result in Bold on top-->
                <td class="ItemName">
                  <xsl:value-of select="@name"/>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td class="ItemName" align="Center">
                    <xsl:value-of select="@grade"/>
                  </td>
                </td>
                <tr></tr>
                <!-- SubTests -->
                <xsl:for-each select="(.)/TestRun">
                  <xsl:choose>
                    <!-- Don't show failed Noise and Drift Tests-->
                    <xsl:when test="(@name='Noise' or @name='Drift')"/>
                    <!-- Don't show tests we want to omit-->
                    <xsl:when test="node()='Omit'"/>
                  <xsl:otherwise>
                      <tr>
                        <td class="SubItemName">
                          &#160;&#160;&#160;&#160;<xsl:value-of select="@name"/>
                        </td>
                        <!-- sub LSL -->
                        <xsl:choose>
                          <xsl:when test="string-length(Result/Property/ValueDouble/@lsl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/Property/ValueDouble/@lsl"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/ValueDouble/@lsl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/ValueDouble/@lsl"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/Property/ValueInteger/@lsl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/Property/ValueInteger/@lsl"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/ValueInteger/@lsl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/ValueInteger/@lsl"/>
                            </td>
                          </xsl:when>
                          <xsl:otherwise>
                            <td></td>
                          </xsl:otherwise>
                        </xsl:choose>
                        <!-- Sub Meas  -->
                        <xsl:if test="string-length(node()[1])>0">
                          <td class="SubItemName" align="center">
                            <xsl:value-of select="node()[1]"/>
                          </td>
                        </xsl:if>
                        <xsl:if test="string-length(node()[1])=0">
                          <td></td>
                        </xsl:if>
                        <!-- sub USL -->
                        <xsl:choose>

                          <xsl:when test="string-length(Result/Property/ValueDouble/@usl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/Property/ValueDouble/@usl"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/ValueDouble/@usl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/ValueDouble/@usl"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/Property/ValueInteger/@usl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/Property/ValueInteger/@usl"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/ValueInteger/@usl)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/ValueInteger/@usl"/>
                            </td>
                          </xsl:when>
                          <xsl:otherwise>
                            <td></td>
                          </xsl:otherwise>
                        </xsl:choose>
                        <!-- Sub uom  -->
                        <xsl:choose>
                          <xsl:when test="string-length(Result/Property/ValueDouble/@uom)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/Property/ValueDouble/@uom"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/ValueDouble/@uom)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/ValueDouble/@uom"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/Property/ValueInteger/@uom)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/Property/ValueInteger/@uom"/>
                            </td>
                          </xsl:when>

                          <xsl:when test="string-length(Result/ValueInteger/@uom)>0">
                            <td class="SubItemName" align="center">
                              <xsl:value-of select="Result/ValueInteger/@uom"/>
                            </td>
                          </xsl:when>

                          <xsl:otherwise>
                            <td></td>
                          </xsl:otherwise>
                        </xsl:choose>
                        <!-- Grade  -->
                        <xsl:if test="string-length(@grade)>0">
                          <td class="SubItemName" align="left">
                            &#160;&#160;&#160;&#160;<xsl:value-of select="@grade"/>
                          </td>
                        </xsl:if>
                      </tr>
                    </xsl:otherwise> <!-- end of check for noise, drift, or Omit-->
                  </xsl:choose> <!--goes with the otherwise right above this-->
                 </xsl:for-each> <!-- with for each test run-->
              </xsl:otherwise>
              <!-- end of sub test-->
            </xsl:choose>
            <!--big choice sub or no-->
            </tr>
              </xsl:otherwise> <!-- with if noise or drift or Omit-->
            </xsl:choose>  <!-- with if noise or drift or Omit-->
          </xsl:for-each>
        </table>
        
        <tr>
          <td>
            <br></br>
          </td>
        </tr>
        
        <tr>
         <td width="100%">
            <h6>
              <xsl:value-of select="UnitReport/TestRun/@name"/>
              Overall Result -
              <xsl:value-of select="UnitReport/TestRun/@grade"/>
            </h6>
          </td>
         </tr>

        <tr>
          <td>
            <br></br>
          </td>
        </tr>

        <table width="100%">
          <tr>
            <td align="center">
              <h5>
                Signed:
              </h5>
            </td>
            <td align="center">
              <h5>
                Date:
              </h5>
            </td>
          </tr>

          <tr>
            <td class="SubItemName">END OF DATA</td>
          </tr>
          
        </table>
        
      </body>
    </html>
  </xsl:template>
  
</xsl:stylesheet>
			
	
