<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



<!-- ******************************************************************************* -->
<!-- The "eventType" parameter is used to filter out which events are                -->
<!-- going to be displayed in the finall generated XHTML output                      -->
<!--                                                                                 -->
<!-- The following values govern specific, single, categories:                       -->
<!-- *********************************************************                       -->
<!-- 'Unknown'	    : Messages that didn't identify what they were                   -->
<!-- 'Error'	    : Fatal problems with functionality                              -->
<!-- 'Warning'	    : Recoverable problems with code                                 -->
<!-- 'Comment'	    : General information and statistics                             -->
<!-- 'Event'	    : Caused by a specific change in state or flow of the game       -->
<!-- 'Debug'	    : Intermediary/Resultant data and state related information      -->

<!-- 'App Message' : App play and AI related messages.                             -->
<!--                                                                                 -->
<!-- The following are combination options for ease of use                           -->
<!-- *****************************************************                           -->
<!-- 'all'	: All the above specific categories                                  -->
<!-- 'failures'	: Only 'Error' and 'Warning'                                         -->
<!-- 'tracking'	: 'Comment', 'Event', 'Debug' and 'App Message'                     -->
<!-- ******************************************************************************* -->
	<xsl:param name="eventType"				select="'all'"/>
	
	
	
<!-- ******************************************************************************* -->
<!-- The "nameSpace" parameter is used to filter the messages depending on the       -->
<!-- general location that the message originated from within the source code        -->
<!--                                                                                 -->
<!-- The following special values are defined:                                       -->
<!-- *****************************************                                       -->

<!-- 'any'          : This will effectively disable namespace filtering              -->
<!--                                                                                 -->
<!-- The following are the currently used namespace names:                           -->
<!-- *****************************************************                           -->
<!-- default        : Originating in the root (unnamed) C++ namespace                -->
<!-- Engines        : The files that make up the core/underlying engine code         -->
<!-- Game           : The files that make up the actual game                         -->
<!-- UI             : The files that make up the user interface (mostly controls)    -->
<!-- Vars           : The data storage components of the code                        -->
<!-- ******************************************************************************* -->
	<xsl:param name="nameSpace"				select="'any'"/>



<!-- ******************************************************************************* -->
<!-- The "specificFile" parameter is used to restrict the messages down to a         -->

<!-- particular file within the C++ code base. There are no particular rules, but    -->
<!-- for obvious reasons the filename should be correct!                             -->
<!-- ******************************************************************************* -->
	<xsl:param name="specificFile"			select="''"/>



<!-- 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 class="titulo">
					Run-Time Log
				</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/>
				<font face="Arial" size="2" color="#AAAAAA">
					This output is displaying events of type 
					<b>
						'<xsl:copy-of select="$eventType"/>'
					</b>
					that originated from
					<b>
						<xsl:copy-of select="$specificFile"/>

					</b>
					within the namespace 
					<b>
						'<xsl:copy-of select="$nameSpace"/>'
					</b>
				</font>
				<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 class="headerData">
			Output level:
		</font>
		<font class="headerOutput">
			<xsl:value-of select="OutputLevel"/>
		</font>
		<br/>

		<font class="headerData">
			Session started at 
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Started/Time"/>
		</font>
		<font class="headerData">
			on 
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Started/Date"/>
		</font>
		<br/>
		
		<font class="headerData">
			Operating environment: 
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Configuration/Environment"/>
		</font>
		<br/>
		
		<font class="headerData">
			System processor: 
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Configuration/Processor/Family"/>
		</font>
		<font class="headerData">
			running at approximately  
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Configuration/Processor/ClockSpeed"/>
		</font>
		<font class="headerData">
			Mhz  
		</font>
		<br/>

		<font class="headerData">
			Memory on start-up: 
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Configuration/Memory/Available"/>
		</font>
		<font class="headerData">
			available from  
		</font>
		<font class="headerOutput">
			<xsl:value-of select="Session/Configuration/Memory/Total"/>
		</font>
		<font class="headerData">
			installed
		</font>
		<br/>
		
		<font class="headerData">
			Total logged events: 
		</font> 
		<font class="headerOutput">
			<xsl:copy-of select="count(../LogEvent)"/>
		</font>			
	</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:if test="$specificFile='' or $specificFile=File">
			<xsl:choose>
				<xsl:when test="Type='Comment'">
					<xsl:if test="$eventType='all' or $eventType='tracking' or $eventType='Comment'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">

							<tr class="commentData">
								<td>				
									<font class="dataIdStyle">
										<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 class="commentMessage">
								<xsl:apply-templates select="Message"/>
							</tr>
						</xsl:if>

					</xsl:if>
					
				</xsl:when>
				<xsl:when test="Type='Unknown'">
					<xsl:if test="$eventType='all' or $eventType='Unknown'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">
							<tr class="unknownData">
								<td>				
									<font class="dataIdStyle">
										<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 class="unknownMessage">
								<xsl:apply-templates select="Message"/>
							</tr>
						</xsl:if>
					</xsl:if>
					
				</xsl:when>
				<xsl:when test="Type='Error'">
					<xsl:if test="$eventType='all' or $eventType='failures' or $eventType='Error'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">

							<tr class="errorData">
								<td>				
									<font class="dataIdStyle">
										<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 class="errorMessage">
								<xsl:apply-templates select="Message"/>
							</tr>
						</xsl:if>
					</xsl:if>

					
				</xsl:when>
				<xsl:when test="Type='Warning'">
					<xsl:if test="$eventType='all' or $eventType='failures' or $eventType='Warning'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">
							<tr class="warningData">
								<td>				
									<font class="dataIdStyle">
										<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 class="warningMessage">
								<xsl:apply-templates select="Message"/>
							</tr>
						</xsl:if>
					</xsl:if>
					
				</xsl:when>
				<xsl:when test="Type='Event'">
					<xsl:if test="$eventType='all' or $eventType='tracking' or $eventType='Event'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">
							<tr class="eventData">
								<td>				
									<font class="dataIdStyle">
										<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 class="eventMessage">
								<xsl:apply-templates select="Message"/>
							</tr>
						</xsl:if>
					</xsl:if>
					
				</xsl:when>

				<xsl:when test="Type='Debug'">
					<xsl:if test="$eventType='all' or $eventType='Debug'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">
							<tr class="debugData">
								<td>				
									<font class="dataIdStyle">
										<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 class="debugMessage">
								<xsl:apply-templates select="Message"/>

							</tr>
						</xsl:if>
					</xsl:if>
					
				</xsl:when>
				<xsl:when test="Type='App Message'">
					<xsl:if test="$eventType='all' or $eventType='tracking' or $eventType='App Message'">
						<xsl:if test="$nameSpace='any' or $nameSpace=NameSpace">
							<tr class="appData">
								<td>				
									<font class="dataIdStyle">
										<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 class="appMessage">
								<xsl:apply-templates select="Message"/>
							</tr>
						</xsl:if>
					</xsl:if>
					
				</xsl:when>
			</xsl:choose>
		</xsl:if>
	</xsl:template>
	
  <!-- This match is for the formatted time output associate with each log entry. -->
  <xsl:template match="TimeIndex">
    <td>
      <font class="dataEventStyle">
        <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 class="dataEventStyle">
        <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 class="dataEventStyle">
        <xsl:apply-templates/>
      </font>
    </td>
  </xsl:template>
	
  <!-- This outputs the line number for the given source code file. -->
  <xsl:template match="LineNumber">
    <td>
      <font class="dataEventStyle">
        <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 class="dataMessageStyle">
        <xsl:apply-templates/>
      </font>
    </td>
  </xsl:template>

</xsl:stylesheet>
