<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- This following section is the entry point for parsing the associated XML        -->
<!-- document. It hands out parsing to the relevent subsections and generally links  -->
	<xsl:template match="/">

		<html>
			<head>
				<title>Log File Viewer</title>
			</head>
			<body>
				<font face="Arial" size="5" color="#2060AA">
					<b>
						<u>
							Run-Time Log
						</u>
					</b>
				</font>
				<br/>
					<xsl:apply-templates select="RunTimeLog/LogHeader"/>
				<br/>
				<br/>
				<b>
					<font face="Arial" size="3" color="#000000">
						Details of selected log entries:
					</font>
				</b>
				<br/>
				<br/>
				<table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#ffffff" bordercolor="#000000">
					<tr>
						<td width="3%"  bgcolor="#000000"><font size="2" face="Arial" color="#FFFFFF"><b><center>#</center></b></font></td>
						<td width="20%" bgcolor="#000000"><font size="2" face="Arial" color="#FFFFFF"><b><center>Time</center></b></font></td>
						<td width="23%" bgcolor="#000000"><font size="2" face="Arial" color="#FFFFFF"><b><center>File</center></b></font></td>
						<td width="50%" bgcolor="#000000"><font size="2" face="Arial" color="#FFFFFF"><b><center>Function</center></b></font></td>
						<td width="4%"  bgcolor="#000000"><font size="2" face="Arial" color="#FFFFFF"><b><center>Line</center></b></font></td>
					</tr>
					<xsl:apply-templates select="RunTimeLog/LogEvent"/>
				</table>

			</body>
		</html>

	</xsl:template>



<!-- This next template match is for the log header, that is the general session     -->
<!-- information and run-time system statistics/configuration                        -->
	<xsl:template match="LogHeader">
		
		<br/>
		<b>
			<font face="Arial" size="3" color="#000000">
				Log file header information:
			</font>
		</b>
		<br/>
		<font face="Arial" size="2" color="#000000">
			Output level:
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="OutputLevel"/>
			</font>
		</i>
		<br/>
		<font face="Arial" size="2" color="#000000">
			Session started at 
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Started/Time"/>
			</font>
		</i>
		<font face="Arial" size="2" color="#000000">
			on 
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Started/Date"/>
			</font>
		</i>
		<br/>
		<font face="Arial" size="2" color="#000000">
			Operating environment: 
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Configuration/Environment"/>
			</font>
		</i>
		<br/>
		<font face="Arial" size="2" color="#000000">
			System processor: 
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Configuration/Processor/Family"/>
			</font>
		</i>
		<font face="Arial" size="2" color="#000000">
			running at approximately  
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Configuration/Processor/ClockSpeed"/>
			</font>
		</i>
		<font face="Arial" size="2" color="#000000">
			Mhz  
		</font>
		<br/>
		<font face="Arial" size="2" color="#000000">
			Memory on start-up: 
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Configuration/Memory/Available"/>
			</font>
		</i>
		<font face="Arial" size="2" color="#000000">
			available from  
		</font>
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:value-of select="Session/Configuration/Memory/Total"/>
			</font>
		</i>
		<font face="Arial" size="2" color="#000000">
			installed
		</font>
		<br/>
		<font face="Arial" size="2" color="#000000">
			Total logged events: 
		</font> 
		<i>
			<font face="Arial" size="2" color="#808080">
				<xsl:copy-of select="count(../LogEvent)"/>
			</font>
		</i>			

	</xsl:template>



<!-- This template match is for each log entry, filtered according to the selected   -->
<!-- type of event filter. For each log entry we add a row to the table.             -->
	<xsl:template match="LogEvent">
	
			<xsl:choose>
				<xsl:when test="Type='Comment'">
							<tr bgcolor="#80FF80" valign="middle" align="center">

								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>

							</tr>
							<tr bgcolor="#AAFFAA">
								<xsl:apply-templates select="Message"/>
							</tr>
				</xsl:when>
				<xsl:when test="Type='Unknown'">
							<tr bgcolor="#EEEEEE" valign="middle" align="center">
							
								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>
								
							</tr>
							<tr bgcolor="#AAAAAA">
								<xsl:apply-templates select="Message"/>
							</tr>
				</xsl:when>
				<xsl:when test="Type='Error'">
							<tr bgcolor="#FF8080" valign="middle" align="center">
							
								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>
								
							</tr>
							<tr bgcolor="#FFAAAA">
								<xsl:apply-templates select="Message"/>
							</tr>
				</xsl:when>
				<xsl:when test="Type='Warning'">
							<tr bgcolor="#FFAA80" valign="middle" align="center">

								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>
								
							</tr>
							<tr bgcolor="#FFDDAA">
								<xsl:apply-templates select="Message"/>
							</tr>
				</xsl:when>
				<xsl:when test="Type='Event'">
							<tr bgcolor="#8080FF" valign="middle" align="center">
							
								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>
								
							</tr>
							<tr bgcolor="#AAAAFF">
								<xsl:apply-templates select="Message"/>
							</tr>
				</xsl:when>
				<xsl:when test="Type='Debug'">
							<tr bgcolor="#FFFF80" valign="middle" align="center">
							
								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>
								
							</tr>
							<tr bgcolor="#FFFF99">
								<xsl:apply-templates select="Message"/>
							</tr>
				</xsl:when>
				<xsl:when test="Type='Game Message'">
							<tr bgcolor="#FF8020" valign="middle" align="center">
							
								<td>				
									<font size="2" face="Arial" color="#202020">
										<center>
											<xsl:value-of select="@id"/>
										</center>
									</font>
								</td>
								
								<xsl:apply-templates select="TimeIndex"/>
								<xsl:apply-templates select="File"/>
								<xsl:apply-templates select="Function"/>
								<xsl:apply-templates select="LineNumber"/>
								
							</tr>
							<tr bgcolor="#FFAA80">
								<xsl:apply-templates select="Message"/>
							</tr>					
				</xsl:when>
			</xsl:choose>

	</xsl:template>
	
	
	
<!-- This match is for the formatted time output associate with each log entry       -->
	<xsl:template match="TimeIndex">
		<td>
			<font size="2" face="Courier New" color="#404040">
				<center>
					<xsl:apply-templates/>
				</center>
			</font>
		</td>
	</xsl:template>



<!-- This match is for the source code filename where this entry originated from     -->
	<xsl:template match="File">
		<td>
			<font size="2" face="Courier New" color="#404040">
				<xsl:apply-templates/>
			</font>
		</td>
	</xsl:template>
	
	
	
<!-- This match outputs the qualified function name where the entry was created      -->
	<xsl:template match="Function">
		<td>
			<font size="2" face="Courier New" color="#404040">
				<xsl:apply-templates/>
			</font>
		</td>
	</xsl:template>
	
	
	
<!-- This outputs the line number for the given source code file.                    -->
	<xsl:template match="LineNumber">
		<td>
			<font size="2" face="Courier New" color="#404040">
				<center>
					<xsl:apply-templates/>
				</center>
			</font>
		</td>
	</xsl:template>



<!-- This match outputs the raw 'Message' data that's sttached to this log entry.    -->
	<xsl:template match="Message">
		<td bgcolor="#FFFFFF">
		</td>
			<td colspan="4">
				<font size="2" face="Arial" color="#000000">
					<b>
						<i>
							<xsl:apply-templates/>
						</i>
					</b>
				</font>
			</td>
	</xsl:template>



</xsl:stylesheet>