﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common">
	<xsl:template match="/">
		<html>
			<head>
				<style>

          body {
          font-family:gt-walsheim-pro;
          }
          table {
          border:0;
          width:100%;
          font-size:10pt;
          }
          .summaryheader {
          background-color:lightgray;
          width:100pt;
          font-weight: bold;
          }
          .summaryvalue {
          background-color:#eeeeee;
          }
          .detailheader {
          background-color:darkblue;
          color:white;
          height:30;
          }
          .detailcategory {
          background-color:lightgray;
          font-size:11pt;
          }
          .detailcriterion {
          background-color:#eeeeee;
          font-size:10pt;
          }
          .detailinfo {
          background-color:#ffffff;
          font-size:9pt;
          }
          .pass {
          background-color:green;
          text-align:center;
          color:white
          }
          .fail {
          background-color:red;
          text-align:center;
          color:white
          }
          .warn {
          background-color:yellow;
          text-align:center;
          }
          .skip {
          background-color:blue;
          text-align:center;
          color:white
          }
          .NA {
          text-align:center;
          }
          .internalinfo {
          background-color:white;
          border: 5px solid;
          border-color: red;
          padding: 0px;
          }
          .internalinfoheader {
          width: auto;
          background: red;
          height: 26px;
          color: white;
          padding-left: 5px;
          }
        </style>
			</head>
			<body>
				<h1>Validation Report</h1>
				<h2></h2>
				<table>
					<xsl:for-each select="/validationreport/summaries/summary">
						<tr>
							<td class="summaryheader">
								<xsl:value-of select="@description" />
							</td>
							<td class="summaryvalue">
								<xsl:value-of select="." />
							</td>
						</tr>
					</xsl:for-each>
				</table>
				<h2></h2>
				<table>
					<col width="50" />
					<col width="90" align="center" />
					<col align="left" />
					<col width="80" align="center" />
					<tr class="detailheader">
						<th>
						</th>
						<th>Criterion #</th>
						<th>Description</th>
						<th>Severity</th>
					</tr>
					<xsl:call-template name="BuildCategory">
						<xsl:with-param name="list" select="/validationreport/validations/validation" />
					</xsl:call-template>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:variable name="numberofcolumn" select="'4'" />
	<xsl:template name="BuildCategory">
		<xsl:param name="list" />
		<xsl:for-each select="$list">
			<xsl:call-template name="BuildValidation">
				<xsl:with-param name="node" select="." />
			</xsl:call-template>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="BuildValidation">
		<xsl:param name="node" />
		<xsl:choose>
			<xsl:when test="count($node/validation) = 0">
				<tr class="detailcriterion">
					<xsl:choose>
						<xsl:when test="$node/@result = 'Passed'">
							<td class="pass">Pass</td>
						</xsl:when>
						<xsl:when test="($node/@result = 'Failed') and ($node/@severity = 'Error')">
							<td class="fail">Fail</td>
						</xsl:when>
						<xsl:when test="($node/@result = 'Failed') and ($node/@severity = 'Warning')">
							<td class="warn">Fail</td>
						</xsl:when>
						<xsl:when test="$node/@result = 'Skipped'">
							<td class="NA">Skip</td>
						</xsl:when>
						<xsl:otherwise>
							<td class="NA">
							</td>
						</xsl:otherwise>
					</xsl:choose>
					<td>
						<xsl:value-of select="$node/@id" />
					</td>
					<td>
						<xsl:value-of select="$node/@description" />
					</td>
					<td>
						<xsl:value-of select="$node/@severity" />
					</td>
				</tr>
				<xsl:if test="count($node/info) &gt; 0">
					<tr class="detailinfo">
						<td colspan="{$numberofcolumn}">
							<ul>
								<xsl:for-each select="$node/info">
									<li>
										<xsl:value-of select="." />
									</li>
								</xsl:for-each>
							</ul>
						</td>
					</tr>
				</xsl:if>
        <xsl:if test="count($node/internal) &gt; 0">
          <tr>
            <td colspan="{$numberofcolumn}" class="internalinfo">
              <div class="internalinfoheader">Internal Error(s)</div>
              <ul>
                <xsl:for-each select="$node/internal">
                  <li>
                    <xsl:value-of select="." />
                  </li>
                </xsl:for-each>
              </ul>
            </td>
          </tr>
        </xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<tr class="detailcategory">
					<td colspan="{$numberofcolumn}">
						<xsl:value-of select="$node/@description" />
					</td>
				</tr>
				<xsl:call-template name="BuildCategory">
					<xsl:with-param name="list" select="$node/validation" />
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>