﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="results">
		<html>
			<head>
				<title>Test Results</title>
			</head>
			<body>
				<xsl:apply-templates select="link" />
				<h1>Test Environment: <xsl:value-of select="description"/></h1>
				<p>Start Time: <xsl:value-of select="start"/><br/>
				End Time: <xsl:value-of select="end"/></p>
				<xsl:apply-templates select="test" />
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="link">
		<p><a href="{@linkdst}"><xsl:value-of select="." /></a></p>
	</xsl:template>
	
	<xsl:template match="test">
		<h2>
			<xsl:choose>
				<xsl:when test="testresult/result='2'">
					<xsl:attribute name="style">
						<xsl:value-of select="'color:#00AA00'" />
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="testresult/result='3'">
					<xsl:attribute name="style">
						<xsl:value-of select="'color:#FF0000'" />
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="testresult/result='4'">
					<xsl:attribute name="style">
						<xsl:value-of select="'color:#FF0000'" />
					</xsl:attribute>
				</xsl:when>
				<xsl:when test="testresult/result='5'">
					<xsl:attribute name="style">
						<xsl:value-of select="'color:#FF0000'" />
					</xsl:attribute>
				</xsl:when>
			</xsl:choose>
			<a href="javascript:void(0)" style="line-height:100%;font-size:100%;font-family:monospace;text-decoration:none;padding:0px;margin:0px;color:black;">
				<xsl:variable name="lid" select="concat('list_', @id)" />
				<xsl:attribute name="onclick">
					var l=document.getElementById(&apos;<xsl:value-of select="$lid"/>&apos;);if(l.style.display==&apos;&apos;){l.style.display=&apos;none&apos;;this.firstChild.data=&apos;+&apos;;}else{l.style.display=&apos;&apos;;this.firstChild.data=&apos;-&apos;;}
				</xsl:attribute>
				+</a>
			Test: 
			<xsl:choose>
				<xsl:when test="name and name!=''">
					<xsl:value-of select="name"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@id"/>
				</xsl:otherwise>
			</xsl:choose>			
		</h2>
		
		<ul style="list-style-type:none;display:none;">
			<xsl:attribute name="id">
				<xsl:value-of select="concat('list_', @id)" />
			</xsl:attribute>

			<xsl:apply-templates select="testresult" />
			
			<li>
				<xsl:apply-templates select="subtests/test" />
			</li>
		</ul>
		
	</xsl:template>

	<xsl:template match="testresult">
		<xsl:param name="indent" select="0" />

		<li>
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td style="vertical-align:top">
						<xsl:choose>
							<xsl:when test="result='1'">
								<p><strong>Running</strong></p>
							</xsl:when>
							<xsl:when test="result='2'">
								<p><strong style="color:#00AA00">OK</strong></p>
							</xsl:when>
							<xsl:when test="result='3'">
								<p><strong style="color:#FF0000">Init failed</strong></p>
							</xsl:when>
							<xsl:when test="result='4'">
								<p><strong style="color:#FF0000">Test failed</strong></p>
							</xsl:when>
							<xsl:when test="result='5'">
								<p><strong style="color:#FF0000">Finish failed</strong></p>
							</xsl:when>
							<xsl:otherwise>
								<p><strong>Not started</strong></p>
							</xsl:otherwise>
						</xsl:choose>
					</td>
			
					<xsl:if test="start and start!='' and end and end!=''">
						<td style="padding-left:1em">
							<p><span style="font-size:80%">Start: <xsl:value-of select="start"/><br/>
							End: <xsl:value-of select="end"/></span></p>
						</td>
					</xsl:if>
				</tr>
			</table>
		</li>
		<li/>
		<li>
			<xsl:copy-of select="message"/>
		</li>
		<xsl:apply-templates select="throwable" />
		<li/>
	</xsl:template>
	
	<xsl:template match="throwable" >
		<li>
			<pre>
				<xsl:value-of select="." />
			</pre>
		</li>

	</xsl:template>
</xsl:stylesheet>