﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates select="/Document/JobSession"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="setHeaderClass">
    <xsl:param name="status"/>
    <xsl:attribute name="style">
      <xsl:text>color: white;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 15px 15px;border: none;font-family: Tahoma;</xsl:text>
      <xsl:choose>
        <xsl:when test="string($status) = 'Success'">
          <xsl:text>background-color: #00B050;</xsl:text>
        </xsl:when>
        <xsl:when test="string($status) = 'Warning'">
          <xsl:text>background-color: #ffd96c;</xsl:text>
        </xsl:when>
        <xsl:when test="string($status) = 'Failed'">
          <xsl:text>background-color: #fb9895;</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>background-color: gray;</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
  </xsl:template>

  <xsl:template name="setCellText">
    <xsl:param name="value"/>
    <xsl:choose>
      <xsl:when test="string-length($value)!=0">
        <xsl:value-of select="$value"/>
      </xsl:when>
      <xsl:otherwise>&#xA0;</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="setCellDetails">
    <xsl:param name="value"/>
    <xsl:choose>
      <xsl:when test="$value/Detail">
        <xsl:for-each select="$value/Detail/text()">
          <xsl:value-of select="."/>
          <xsl:element name="br"/>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>&#xA0;</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="JobSession">
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'"/>
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <!-- Container -->
    <table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">
      <tr>
        <td style="border: none;font-family: Tahoma;font-size: 12px;padding:0;border-width: 0 0 0 0;">
          <!-- Header -->
          <table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">
            <tr>
              <td width="80%" style="padding: 0;font-family: Tahoma;font-size: 12px;border-color: #a7a9ac;border-width: 0 0 0 0;border-style: solid;">
                <xsl:call-template name="setHeaderClass">
                  <xsl:with-param name="status" select="./Status"/>
                </xsl:call-template>
                <xsl:value-of select="./JobType"/>
                <xsl:text> for </xsl:text>
                <xsl:value-of select="/Document/ServerName"/>
                <div style="margin-top: 5px;font-size: 12px;">
                  <xsl:text>To: </xsl:text>
                  <xsl:value-of select="./JobOptions/BackupRepositoryName"/>
                </div>
              </td>
              <td style="padding: 0;font-family: Tahoma;font-size: 12px;border-color: #a7a9ac;border-width: 0 0 0 0;border-style: solid;">
                <xsl:call-template name="setHeaderClass">
                  <xsl:with-param name="status" select="./Status"/>
                </xsl:call-template>
                <xsl:value-of select="./Status" />
                <div style="margin-top: 5px;font-size: 12px;">
                  <xsl:choose>
                    <xsl:when test="./Entries/Entry">
                      <xsl:value-of select="count(./Entries/Entry)"/>
                      catalogs processed
                    </xsl:when>
                    <xsl:otherwise>&#xA0;</xsl:otherwise>
                  </xsl:choose>
                </div>
              </td>
            </tr>
          </table>
          <!-- Data -->
          <table cellspacing="0" cellpadding="0" width="100%" class="data" style="border-collapse: collapse;">
            <tr>
              <td colspan="5" style="font-family: Tahoma;height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 2px 3px 2px 3px;color: #626365;border: 1px solid #a7a9ac;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="/Document/CreationTime"/>
                </xsl:call-template>
              </td>
            </tr>
            <tr>
              <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Start time</td>
              <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="./StartTime"/>
                </xsl:call-template>
              </td>
              <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Data size</td>
              <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="./DataSize"/>
                </xsl:call-template>
              </td>
              <td rowspan="3" style="font-family: Tahoma;font-size: 10px;vertical-align: top;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellDetails">
                  <xsl:with-param name="value" select="./Details"/>
                </xsl:call-template>
              </td>
            </tr>
            <tr>
              <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">End time</td>
              <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="./EndTime"/>
                </xsl:call-template>
              </td>
              <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Backup size</td>
              <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="./BackupSize"/>
                </xsl:call-template>
              </td>
            </tr>
            <tr>
              <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Duration</td>
              <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="./Duration"/>
                </xsl:call-template>
              </td>
              <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Compression</td>
              <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                <xsl:call-template name="setCellText">
                  <xsl:with-param name="value" select="./PackRatio"/>
                </xsl:call-template>
              </td>
            </tr>
            <xsl:if test="./Entries/Entry">
              <tr>
                <td colspan="5" style="font-family: Tahoma;height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 2px 3px 2px 3px;color: #626365;border: 1px solid #a7a9ac;border: 1px solid #a7a9ac;">Details</td>
              </tr>
              <tr>
                <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Catalog</td>
                <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Items</td>
                <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Size</td>
                <td style="font-family: Tahoma;font-size: 12px;font-weight: bold;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">Packed</td>
                <td rowspan="3" style="font-family: Tahoma;font-size: 12px;vertical-align: top;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                  <xsl:attribute name="rowspan">
                    <xsl:value-of select="count(./Entries/Entry) + 1"/>
                  </xsl:attribute>
                  &#xA0;
                </td>
              </tr>
              <xsl:for-each select="./Entries/Entry">
                <tr>
                  <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                    <xsl:call-template name="setCellText">
                      <xsl:with-param name="value" select="Name"/>
                    </xsl:call-template>
                  </td>
                  <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                    <xsl:call-template name="setCellText">
                      <xsl:with-param name="value" select="Items"/>
                    </xsl:call-template>
                  </td>
                  <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                    <xsl:call-template name="setCellText">
                      <xsl:with-param name="value" select="DataSize"/>
                    </xsl:call-template>
                  </td>
                  <td style="font-family: Tahoma;font-size: 12px;white-space: nowrap;width: 125px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;">
                    <xsl:call-template name="setCellText">
                      <xsl:with-param name="value" select="BackupSize"/>
                    </xsl:call-template>
                  </td>
                </tr>
              </xsl:for-each>
            </xsl:if>
          </table>
          <!-- Product -->
          <table cellspacing="0" cellpadding="0" width="100%" border="0" style="border-collapse: collapse;">
            <tr>
              <td style="padding: 0;font-family: Tahoma;height: 25px;vertical-align: bottom;font-size: 12px;color: #626365;border: none;">
                Veeam Backup &amp; Replication <xsl:value-of select="/Document/Shell_App_Version"/>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </xsl:template>

</xsl:stylesheet>
