<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<!-- Root template -->
<xsl:template match="/">
	<html>
		<head>
			<title>Summary Statistics</title>
			<link href="StatsReport.css" type="text/css" rel="stylesheet"/>
		</head>
		<body>
			<xsl:apply-templates select="StatsReport"/>
		</body>
	</html>
</xsl:template>

<!-- StatsReport template -->
<xsl:template match="StatsReport"><xsl:apply-templates select="SummaryStatistics"/></xsl:template>

<!-- SumStats template -->
<xsl:template match="SummaryStatistics">
	<h1>Summary Statistics</h1>
	<xsl:apply-templates select="Summary"/>
	<table class="tbl">
		<thead>
			<tr>
				<th class="hl">Group</th>
				<th class="hr" style="width:100px;">Value</th>
			</tr>
		</thead>
		<tbody>
			<xsl:apply-templates select="Stats"/>
		</tbody>
	</table>
</xsl:template>

<!-- StatsReport/SummaryStatistics/Summary template -->
<xsl:template match="Summary">
	<table border="0">
		<tr>
			<td class="bg"><b>Time Saved:</b></td>
			<td class="bg"><xsl:apply-templates select="TimeSaved"/></td>
		</tr>
		<tr>
			<td class="bg"><b>Start Time:</b></td>
			<td class="bg"><xsl:value-of select="StartDate"/> <xsl:value-of select="StartTime"/></td>
		</tr>
		<tr>
			<td class="bg"><b>Duration:</b></td>
			<td class="bg"><xsl:value-of select="Duration"/></td>
		</tr>
	</table>
</xsl:template>

<!-- StatsReport/SummaryStatistics/Summary/TimeSaved template -->
<xsl:template match="TimeSaved"><xsl:eval>formatDate(this.nodeTypedValue, "MMMM dd',' yyyy")</xsl:eval> <xsl:eval>formatTime(this.nodeTypedValue, "hh:mm tt")</xsl:eval></xsl:template>

<!-- StatsReport/SummaryStatistics/Stats template -->
<xsl:template match="Stats"><xsl:apply-templates select="Snapshot"/></xsl:template>

<!-- StatsReport/SummaryStatistics/Stats/Snapshot template -->
<xsl:template match="Snapshot">
	<tr>
		<td class="snapshot" colspan="2"><xsl:value-of select="@Name"/></td>
	</tr>
	<xsl:apply-templates select="Group"/>
</xsl:template>

<!-- StatsReport/SummaryStatistics/Stats/Snapshot/Group template -->
<xsl:template match="Group">
	<tr>
		<td class="group" colspan="2"><xsl:value-of select="@Name"/></td>
	</tr>
	<xsl:apply-templates select="SummaryStat"/>
</xsl:template>

<!-- StatsReport/SummaryStatistics/Stats/Snapshot/Group/SummaryStat template -->
<xsl:template match="SummaryStat">
	<tr>
		<td class="rl"><xsl:value-of select="Name"/></td>
		<td class="rr"><xsl:value-of select="BytesValue"/></td>
	</tr>
</xsl:template>

</xsl:stylesheet>
