<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="document/requests/request">
          <h1>
            Request
            <xsl:value-of select="requestId"/>
          </h1>
          Organisation:
          <xsl:value-of select="organization"/>
          <br/>
          Status:
          <xsl:value-of select="status"/>
          <br/>
          Type:
          <xsl:value-of select="type"/>
          <br/>
          Purpose:
          <xsl:value-of select="purpose"/>
          <h2>Contact info</h2>
          Submitter:
          <xsl:value-of select="contact/submitterName"/>
          <br/>
          Contact:
          <xsl:value-of select="contact/contactName"/>
          ,
          <xsl:value-of select="contact/contactEmail"/>
          ,
          <xsl:value-of select="contact/contactPhone"/>
          <h2>Dates</h2>
          Last Modified Date:
          <xsl:call-template name="dateFormat">
            <xsl:with-param name="date">
              <xsl:value-of select="lastModifiedDate"/>
            </xsl:with-param>
          </xsl:call-template>
          <br/>
          Timestamp:
          <xsl:call-template name="dateFormat">
            <xsl:with-param name="date">
              <xsl:value-of select="timestamp"/>
            </xsl:with-param>
          </xsl:call-template>
          <br/>
          Planned start:
          <xsl:call-template name="dateFormat">
            <xsl:with-param name="date">
              <xsl:value-of select="ecp/period/plannedStartDate"/>
            </xsl:with-param>
          </xsl:call-template>
          <br/>
          Planned end:
          <xsl:call-template name="dateFormat">
            <xsl:with-param name="date">
              <xsl:value-of select="ecp/period/plannedEndDate"/>
            </xsl:with-param>
          </xsl:call-template>
          <br/>
          Actual start:
          <xsl:call-template name="dateFormat">
            <xsl:with-param name="date">
              <xsl:value-of select="ecp/period/actualStartDate"/>
            </xsl:with-param>
          </xsl:call-template>
          <br/>
          Actual end:
          <xsl:call-template name="dateFormat">
            <xsl:with-param name="date">
              <xsl:value-of select="ecp/period/actualEndDate"/>
            </xsl:with-param>
          </xsl:call-template>
          <br/>
          Cycle:
          <xsl:value-of select="period/cycle"/>
          <xsl:choose>
            <xsl:when test="cycle = 'D'">(Daily)</xsl:when>
            <xsl:when test="cycle = 'C'">(Continuous)</xsl:when>
          </xsl:choose>
          <br/>
          Weekends:
          <xsl:value-of select="period/weekends"/>
          <br/>
          One At A Time:
          <xsl:value-of select="period/oneAtATime"/>
          <h2>Cost</h2>
          Cancel Cost:
          <xsl:value-of select="cost/cancelCost"/>
          <br/>
          Defer Cost:
          <xsl:value-of select="cost/deferCost"/>
          <br/>
          Recall Cost:
          <xsl:value-of select="cost/recallCost"/>
          <br/>
          Cost Comments:
          <xsl:value-of select="cost/costComments"/>
          <br/>
          <h2>Comments</h2>
          MP comments:
          <xsl:value-of select="mpComments"/>
          <br/>
          IESO comments:
          <xsl:value-of select="iesoComments"/>
          <h2>Equipment condition plans</h2>
          <table border="1">
            <tr>
              <th>ID</th>
              <th>Station</th>
              <th>Station2</th>
              <th>Eqp. category</th>
              <th>Eqp. name</th>
              <th>Recall Time</th>
              <th>Recall Units</th>
              <th>Condition Type</th>
              <th>Derate (MW)</th>
              <th>Derate (MX in)</th>
              <th>Derate (MX out)</th>
              <th>Derate (MVA)</th>
            </tr>
            <xsl:for-each select="ecp">
              <tr>
                <td>
                  <xsl:value-of select="ecpId"/>
                </td>
                <td>
                  <xsl:value-of select="equipment/station"/>
                </td>
                <td>
                  <xsl:value-of select="equipment/station2"/>
                </td>
                <td>
                  <xsl:value-of select="equipment/type"/>
                </td>
                <td>
                  <xsl:value-of select="equipment/name"/>
                </td>
                <td>
                  <xsl:value-of select="recall/recallTime"/>
                </td>
                <td>
                  <xsl:value-of select="recall/recallUnits"/>
                </td>
                <td>
                  <xsl:value-of select="condition/type"/>
                </td>
                <td>
                  <xsl:value-of select="condition/derateToMW"/>
                </td>
                <td>
                  <xsl:value-of select="condition/derateToMxIn"/>
                </td>
                <td>
                  <xsl:value-of select="condition/derateToMxOut"/>
                </td>
                <td>
                  <xsl:value-of select="condition/derateToMVA"/>
                </td>
              </tr>
            </xsl:for-each>
          </table>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="dateFormat">
    <xsl:param name="date"/>
    <xsl:variable name="monthNum" select="substring($date,6,2)"/>
    <xsl:value-of select="substring($date,1,4)"/>
    ,
    <xsl:choose>
      <xsl:when test="$monthNum = 01">January</xsl:when>
      <xsl:when test="$monthNum = 02">February</xsl:when>
      <xsl:when test="$monthNum = 03">March</xsl:when>
      <xsl:when test="$monthNum = 04">April</xsl:when>
      <xsl:when test="$monthNum = 05">May</xsl:when>
      <xsl:when test="$monthNum = 06">June</xsl:when>
      <xsl:when test="$monthNum = 07">July</xsl:when>
      <xsl:when test="$monthNum = 08">August</xsl:when>
      <xsl:when test="$monthNum = 09">September</xsl:when>
      <xsl:when test="$monthNum = 10">October</xsl:when>
      <xsl:when test="$monthNum = 11">November</xsl:when>
      <xsl:when test="$monthNum = 12">December</xsl:when>
    </xsl:choose>
    &#160;
    <xsl:value-of select="substring($date,9,2)"/>
    ,
    <xsl:value-of select="substring($date,12,5)"/>
  </xsl:template>
</xsl:stylesheet>

