<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:template name="translateBR">
    <xsl:param name="data"/>

    <xsl:variable name="br">
      <xsl:text>&lt;br /&gt;</xsl:text>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="contains($data, $br)">
        <xsl:value-of select="substring-before($data, $br)"/>
        <br/>
        <xsl:call-template name="translateBR">
          <xsl:with-param name="data">
            <xsl:value-of select="substring-after($data, $br)"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$data"/>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

  <xsl:attribute-set name="row-column-span-style">
    <xsl:attribute name="rowspan">3</xsl:attribute>
    <xsl:attribute name="colspan">3</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="row-span-style">
    <xsl:attribute name="rowspan">3</xsl:attribute>
  </xsl:attribute-set>
    
  <xsl:template match="/">

    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

    <html>
      <head>
        <META http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
          table{border-collapse: collapse;}
          table td{padding: 0px;font-family: Tahoma;font-size: 12px;}
          table.inner tr{height: 17px;}
          table.inner td{padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;}
          .reportHeader{font-size: 13px;border: none;padding: 0 0 15px 0px;vertical-align: bottom;height: 50px;}
          .reportHeader span{font-size: 14px;font-weight: bold;padding: 0;}
          .jobHeader_success{background-color: #00B050;color: White;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 15px 15px;}
          .jobHeader_error{background-color: #fb9895;color: White;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 15px 15px;}
          .jobHeader_warning{background-color: #ffd96c;color: White;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 15px 15px;}
          .jobDescription{margin-top: 5px;font-size: 12px;}
          table.inner .sessionDetails{height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 5px 0 0 15px;color: #626365;}
          table.inner .processObjects{height: 35px;background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 5px 0 0 15px;color: #626365;}
          .processObjectsHeader td{background-color: #e3e3e3;padding: 3px 3px 3px 3px;border-top: none;}

          .status_success {background-color: #00B050;}
          .status_error {background-color: #fb9895;}
          .status_warning {background-color: #ffd96c;}

          .success{color: #00B050;}
          .warning{color: #FFC000;}
          .error{color: #FF0000;}
          .small_label{font-size: 10px;}
        </style>
      </head>
      <body>
        <table cellspacing="0" cellpadding="0" width="100%" border="0">
          <xsl:for-each select="/Document/JobSession">
            <tr>
              <td style="border:none; padding: 0px;">
                <table cellspacing="0" cellpadding="0" width="100%" border="0">
                  <tr>
                    <td style='width: 80%;border: none;'>
                      <xsl:attribute name="class">
                        <xsl:text>jobHeader_</xsl:text>
                        <xsl:choose>
                          <xsl:when test="./Status = 'InProgress'">
                            <xsl:choose>
                              <xsl:when test="count(./TaskSession[Status = 'Error']) > 0">error</xsl:when>
                              <xsl:when test="count(./TaskSession[Status = 'Warning']) > 0">warning</xsl:when>
                              <xsl:otherwise>success</xsl:otherwise>
                            </xsl:choose>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:value-of select="translate(./Status, $uppercase, $smallcase)" />
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:attribute>

                      <xsl:value-of select="./JobType" />
                      <xsl:text> job: </xsl:text>
                      <xsl:value-of select="./JobName" />
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="./JobMode" />

                      <div class="jobDescription">
                        <xsl:value-of select="./JobDescription" />
                      </div>
                    </td>
                    <td style='border: none;'>
                      <xsl:attribute name="class">
                        <xsl:text>jobHeader_</xsl:text>
                        <xsl:choose>
                          <xsl:when test="./Status = 'InProgress'">
                            <xsl:choose>
                              <xsl:when test="count(./TaskSession[Status = 'Error']) > 0">error</xsl:when>
                              <xsl:when test="count(./TaskSession[Status = 'Warning']) > 0">warning</xsl:when>
                              <xsl:otherwise>success</xsl:otherwise>
                            </xsl:choose>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:value-of select="translate(./Status, $uppercase, $smallcase)" />
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:attribute>

                      <xsl:value-of select="./Status" />

                      <div class="jobDescription">
                        <xsl:value-of select="./ProcessedObject" />
                        of
                        <xsl:value-of select="./TotalObjects" />
                        <xsl:choose>
                          <xsl:when test="./EDbJobType = '24'">
                            files processed
                          </xsl:when>
                          <xsl:when test="./EDbJobType = '28'">
                            backups processed
                          </xsl:when>
                          <xsl:otherwise>
                            VMs processed
                          </xsl:otherwise>
                        </xsl:choose>
                      </div>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="border: none; padding: 0px;">
                      <table width="100%" cellspacing="0" cellpadding="0" class="inner" border="0" style='margin: 0px;'>
                        <tr>
                          <td colspan="9" class="sessionDetails" style='border-bottom: none;'>
                            <span>
                              <xsl:value-of select="./CreationTime" />
                            </span>
                          </td>
                        </tr>
                        <tr>
                          <td nowrap="" style="width: 1%;">
                            <b>Success</b>
                          </td>
                          <td nowrap="" style="width:85px;">
                            <xsl:value-of select="./SuccessfulObjects" />
                          </td>

                          <td nowrap="" style="width:85px;">
                            <b>Start time</b>
                          </td>
                          <td nowrap="" style="width:85px;">
                            <xsl:value-of select="./StartTime" />
                          </td>

                          <td nowrap="" style="width:85px;">
                            <b>Total size</b>
                          </td>
                          <td nowrap="" style="width:85px;">
                            <xsl:value-of select="./TotalSize" />
                          </td>

                          <xsl:choose>
                            <xsl:when test="./EDbJobType != '24' and ./EDbJobType != '28'">
                              <td nowrap="" style="width:85px;">
                                <b>Backup size</b>
                              </td>
                              <td nowrap="" style="width:85px;">
                                <xsl:value-of select="./BackupSize" />
                              </td>
                            </xsl:when>
                          </xsl:choose>
                          <td xsl:use-attribute-sets="row-span-style">
                            <xsl:choose>
                              <xsl:when test="./EDbJobType = '24' or ./EDbJobType = '28'">
                                <xsl:attribute name="colspan">3</xsl:attribute>
                              </xsl:when>
                            </xsl:choose>
                            <span class='small_label'>
                              <xsl:for-each select="./Details">
                                <xsl:call-template name="translateBR">
                                  <xsl:with-param name="data">
                                    <xsl:value-of select="." />
                                  </xsl:with-param>
                                </xsl:call-template>
                              </xsl:for-each>
                            </span>
                          </td>
                        </tr>

                        <tr>
                          <td nowrap="">
                            <b>Warning</b>
                          </td>
                          <td>
                            <xsl:value-of select="./WarningObjects" />
                          </td>

                          <td nowrap="">
                            <b>End time</b>
                          </td>
                          <td nowrap="">
                            <xsl:value-of select="./EndTime" />
                          </td>

                          <td nowrap="">
                            <b>Data read</b>
                          </td>
                          <td nowrap="">
                            <xsl:value-of select="./DataRead" />
                          </td>
                          <xsl:choose>
                            <xsl:when test="./EDbJobType != '24' and ./EDbJobType != '28'">
                              <td nowrap="">
                                <b>Dedupe</b>
                              </td>
                              <td nowrap="">
                                <xsl:value-of select="./Dedupe" />
                              </td>
                            </xsl:when>
                          </xsl:choose>
                        </tr>

                        <tr>
                          <td nowrap="">
                            <b>Error</b>
                          </td>
                          <td>
                            <xsl:value-of select="./FailedObjects" />
                          </td>

                          <td nowrap="">
                            <b>Duration</b>
                          </td>
                          <td nowrap="">
                            <xsl:value-of select="./Duration" />
                          </td>

                          <td nowrap="">
                            <b>Transferred</b>
                          </td>
                          <td nowrap="">
                            <xsl:value-of select="./DataTransferred" />
                          </td>
                          <xsl:choose>
                            <xsl:when test="./EDbJobType != '24' and ./EDbJobType != '28'">
                              <td nowrap="">
                                <b>Compression</b>
                              </td>
                              <td nowrap="">
                                <xsl:value-of select="./Compression" />
                              </td>
                            </xsl:when>
                          </xsl:choose>
                        </tr>

                        <tr>
                          <td colspan="9" nowrap="" class="processObjects" >
                            Details
                          </td>
                        </tr>
                        <tr class="processObjectsHeader" style="height: 23px">
                          <td nowrap="">
                            <b>Name</b>
                          </td>
                          <td nowrap="">
                            <b>Status</b>
                          </td>
                          <td nowrap="">
                            <b>Start time</b>
                          </td>
                          <td nowrap="">
                            <b>End time</b>
                          </td>
                          <td nowrap="">
                            <b>Size</b>
                          </td>
                          <td nowrap="">
                            <b>Read</b>
                          </td>
                          <td nowrap="">
                            <b>Transferred</b>
                          </td>
                          <td nowrap="">
                            <b>Duration</b>
                          </td>
                          <td>
                            <b>Details</b>
                          </td>
                        </tr>

                        <xsl:for-each select="./TaskSession">
                          <tr>
                            <td nowrap="">
                              <xsl:value-of select="./ObjectName" />
                            </td>
                            <td nowrap="">
                              <span>
                                <xsl:attribute name="class">
                                  <xsl:value-of select="translate(./Status, $uppercase, $smallcase)" />
                                </xsl:attribute>
                                <xsl:value-of select="./Status" />
                              </span>
                            </td>
                            <td nowrap="">
                              <xsl:value-of select="./StartTime" />
                            </td>
                            <td nowrap="">
                              <xsl:value-of select="./EndTime" />
                            </td>
                            <td nowrap="">
                              <xsl:value-of select="./Size" />
                            </td>
                            <td nowrap="">
                              <xsl:value-of select="./Read" />
                            </td>
                            <td nowrap="">
                              <xsl:value-of select="./Transferred" />
                            </td>
                            <td nowrap="">
                              <xsl:value-of select="./Duration" />
                            </td>
                            <td>
                              <span class='small_label'>
                                <xsl:for-each select="./Details">
                                  <xsl:call-template name="translateBR">
                                    <xsl:with-param name="data">
                                      <xsl:value-of select="." />
                                    </xsl:with-param>
                                  </xsl:call-template>
                                </xsl:for-each>
                              </span>
                            </td>
                          </tr>
                        </xsl:for-each>
                      </table>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>

            <tr>
              <td>&#160;</td>
            </tr>
          </xsl:for-each>
          
          <xsl:choose>
            <xsl:when test="/Document/WriteSignature = 'true'">
              <tr>
                <td style="font-size:12px;color:#626365">
                  Veeam Backup &amp; Replication <xsl:value-of select="/Document/Shell_App_Version" />
                </td>
              </tr>
            </xsl:when>
          </xsl:choose>
        </table>
      </body>
    </html>

  </xsl:template>

</xsl:stylesheet>