Contributed by Eugen Treise
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@257 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 28eb6e2b0d3eb851b9c4f71f84ae6bb1adc62c39 Former-commit-id: 0a8559ec091c9478d8f3a1ddd14fc4019769c595
This commit is contained in:
parent
4045527417
commit
5b918c64de
1 changed files with 186 additions and 113 deletions
|
@ -1,14 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
|
||||
<xsl:output method="html"/>
|
||||
|
||||
<!-- This xsl file was made to format results-*.xml files, which are created by torcs
|
||||
after a race, into readable html files.
|
||||
-->
|
||||
<!-- Usage: Open results-*.xml file (it must have a reference to this file) in your browser,
|
||||
or use an xslt processor to convert the xml file to a html file.
|
||||
-->
|
||||
<!-- This xsl file was made to format results-*.xml files, which are created by torcs after a race, into readable html files. -->
|
||||
<!-- Usage: Open results-*.xml file (it must have a reference to this file) in your browser, or use an xslt processor to convert the xml file to a html file. -->
|
||||
|
||||
<!-- Template for the params element -->
|
||||
<xsl:template match="/params">
|
||||
|
@ -34,6 +30,11 @@
|
|||
</xsl:when>
|
||||
<xsl:when test="$Section = 'Standings'">
|
||||
<xsl:call-template name="Standings"/>
|
||||
<!-- Results for multiple tracks available -->
|
||||
<xsl:if test="../section[@name='Current']/attnum[@name='current track']/@val > 1">
|
||||
<HR/>
|
||||
<xsl:call-template name="Summary"/>
|
||||
</xsl:if>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="Track"/>
|
||||
|
@ -51,7 +52,7 @@
|
|||
<h4>Section <xsl:value-of select="@name"/>:</h4>
|
||||
<!-- print all attributes and their values of all child elements in the current section -->
|
||||
<xsl:for-each select="*">
|
||||
<xsl:value-of select="@name"/> = <xsl:value-of select="@val"/> <br/>
|
||||
<xsl:value-of select="@name"/> = <xsl:value-of select="@val"/><br/>
|
||||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
|
||||
|
@ -59,9 +60,7 @@
|
|||
<!-- Template for "Trackname" sections -->
|
||||
<!-- Call different templates for Practice and other Race sessions. -->
|
||||
<xsl:template name="Track">
|
||||
<h2>
|
||||
Track: <xsl:value-of select="@name"/>
|
||||
</h2>
|
||||
<h2>Track: <xsl:value-of select="@name"/></h2>
|
||||
<xsl:choose>
|
||||
<xsl:when test="section[@name='Results']/section[1]/@name = 'Practice'">
|
||||
<xsl:call-template name="Practice"/>
|
||||
|
@ -73,12 +72,12 @@
|
|||
</xsl:template>
|
||||
|
||||
|
||||
<!-- Template for Race sections with several drivers -->
|
||||
<!-- Template for Qualifying and Race sections with several drivers -->
|
||||
<xsl:template name="Race">
|
||||
<xsl:for-each select="section[@name='Results']/section">
|
||||
<h3><xsl:value-of select="@name"/></h3>
|
||||
<xsl:for-each select="*[@val]">
|
||||
<xsl:value-of select="@name"/> = <xsl:value-of select="@val"/> <br/>
|
||||
<xsl:value-of select="@name"/> = <xsl:value-of select="@val"/><br/>
|
||||
</xsl:for-each>
|
||||
<p>
|
||||
<table border="1">
|
||||
|
@ -90,54 +89,69 @@
|
|||
</xsl:for-each>
|
||||
</tr>
|
||||
<xsl:for-each select="section[@name='Rank']/section">
|
||||
|
||||
<!-- choose an other format for human driver, for drivers with points and for drivers with high damage -->
|
||||
<xsl:variable name="FontWeight">
|
||||
<xsl:choose>
|
||||
<xsl:when test="attstr[@name='module' and @val='human']">
|
||||
<xsl:value-of select="'bold'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'normal'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="TextColor">
|
||||
<xsl:choose>
|
||||
<xsl:when test="attnum[@name='points' and @val>0]">
|
||||
<xsl:value-of select="'blue'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'black'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="BGColor">
|
||||
<xsl:choose>
|
||||
<xsl:when test="attnum[@name='dammages' and @val>10000]">
|
||||
<xsl:value-of select="'lightgrey'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'white'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- set format for the next row -->
|
||||
<tr>
|
||||
<xsl:attribute name="style">
|
||||
<xsl:text>font-weight:</xsl:text>
|
||||
<xsl:value-of select="$FontWeight"/>
|
||||
<xsl:text>; color:</xsl:text>
|
||||
<xsl:value-of select="$TextColor"/>
|
||||
<xsl:text>; background-color:</xsl:text>
|
||||
<xsl:value-of select="$BGColor"/>
|
||||
<xsl:if test="attstr[@name='module']/@val = 'human'">
|
||||
<xsl:text>font-weight:bold;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="attnum[@name='points']/@val > 0">
|
||||
<xsl:text>color:blue;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:if test="attnum[@name='dammages']/@val > 10000">
|
||||
<xsl:text>background-color:lightgrey</xsl:text>
|
||||
</xsl:if>
|
||||
</xsl:attribute>
|
||||
|
||||
<!-- Table content (row) -->
|
||||
<td> <xsl:value-of select="@name"/> </td>
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains(../../@name, 'Race')">
|
||||
<xsl:variable name="PosGain" select="attnum[@name='index']/@val + 1 - @name"/>
|
||||
<xsl:variable name="PosSymbol">
|
||||
<xsl:choose>
|
||||
<xsl:when test="$PosGain > 0">
|
||||
<xsl:value-of select="'▲'"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$PosGain < 0">
|
||||
<xsl:value-of select="'▼'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'-'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
<td>
|
||||
<xsl:if test="$PosGain != 0">
|
||||
<xsl:attribute name="style">
|
||||
<xsl:text>color:</xsl:text>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$PosGain > 0">
|
||||
<xsl:value-of select="'green'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'red'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="@name"/>
|
||||
<xsl:text> (</xsl:text>
|
||||
<xsl:value-of select="$PosSymbol"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$PosGain > 0">
|
||||
<xsl:value-of select="$PosGain"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="$PosGain < 0">
|
||||
<xsl:value-of select="-$PosGain"/>
|
||||
</xsl:when>
|
||||
</xsl:choose>
|
||||
<xsl:text>)</xsl:text>
|
||||
</td>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<td><xsl:value-of select="@name"/></td>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:for-each select="*">
|
||||
<td>
|
||||
<xsl:call-template name="FormatedOutput">
|
||||
|
@ -156,19 +170,17 @@
|
|||
<!-- Template for Practice section -->
|
||||
<xsl:template name="Practice">
|
||||
<xsl:for-each select="section[@name='Results']/section">
|
||||
<h3><xsl:value-of select="@name"/> </h3>
|
||||
<!-- print all attributes with a value -->
|
||||
<xsl:for-each select="*[@val]">
|
||||
<xsl:value-of select="@name"/> = <xsl:value-of select="@val"/> <br/>
|
||||
</xsl:for-each>
|
||||
<xsl:value-of select="count(section)"/> laps<br/>
|
||||
<xsl:variable name="TotalTime" select="sum(//attnum[@name='time']/@val)"/>
|
||||
total practice time: <xsl:value-of select="floor($TotalTime div 60)"/> min <xsl:value-of select="round($TotalTime mod 60)"/> s<br/>
|
||||
<h3><xsl:value-of select="@name"/></h3>
|
||||
Driver: <xsl:value-of select="attstr[@name='driver name']/@val"/><br/>
|
||||
<xsl:variable name="TotalLaps" select="count(section)"/>
|
||||
<xsl:variable name="TotalTime" select="sum(section/attnum[@name='time']/@val)"/>
|
||||
<xsl:value-of select="$TotalLaps"/> laps in <xsl:value-of select="floor($TotalTime div 60)"/> min <xsl:value-of select="round($TotalTime mod 60)"/> s<br/>
|
||||
<p>
|
||||
<table border="1">
|
||||
<!-- Table Head -->
|
||||
<tr>
|
||||
<th>Lap</th>
|
||||
<th>time diff</th>
|
||||
<xsl:for-each select="section[1]/*">
|
||||
<th><xsl:value-of select="@name"/></th>
|
||||
</xsl:for-each>
|
||||
|
@ -177,11 +189,20 @@
|
|||
<!-- Table content (row) -->
|
||||
<xsl:for-each select="section">
|
||||
<tr>
|
||||
<!-- fastest lap -->
|
||||
<xsl:if test="attnum[@name='time']/@val = ../section[$TotalLaps]/attnum[@name='best lap time']/@val">
|
||||
<xsl:attribute name="style">
|
||||
<xsl:text>font-weight:bold</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:if>
|
||||
<td><xsl:value-of select="@name"/></td>
|
||||
<td>
|
||||
<xsl:call-template name="FormatTime">
|
||||
<xsl:with-param name="time" select="attnum[@name='time']/@val - ../section[$TotalLaps]/attnum[@name='best lap time']/@val"/>
|
||||
</xsl:call-template>
|
||||
</td>
|
||||
<xsl:for-each select="*">
|
||||
<td>
|
||||
<xsl:call-template name="FormatedOutput"/>
|
||||
</td>
|
||||
<td><xsl:call-template name="FormatedOutput"/></td>
|
||||
</xsl:for-each>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
|
@ -193,7 +214,12 @@
|
|||
|
||||
<!-- Template for Standings section -->
|
||||
<xsl:template name="Standings">
|
||||
<h3><xsl:value-of select="@name"/></h3>
|
||||
<xsl:variable name="TrackCount" select="../section[@name='Current']/attnum[@name='current track']/@val"/>
|
||||
<h3><xsl:value-of select="@name"/>
|
||||
<xsl:if test="$TrackCount > 1">
|
||||
after <xsl:value-of select="$TrackCount"/> races
|
||||
</xsl:if>
|
||||
</h3>
|
||||
<p>
|
||||
<table border="1">
|
||||
<!-- Table header -->
|
||||
|
@ -204,46 +230,30 @@
|
|||
</tr>
|
||||
|
||||
<xsl:for-each select="*">
|
||||
|
||||
<!-- choose an other format for human driver and for drivers with points -->
|
||||
<xsl:variable name="FontWeight">
|
||||
<!-- highlight player and drivers with points -->
|
||||
<tr>
|
||||
<xsl:attribute name="style">
|
||||
<xsl:if test="attstr[@name='module']/@val = 'human' or attnum[@name='points']/@val > 0">
|
||||
<xsl:text>font-weight:bold;</xsl:text>
|
||||
</xsl:if>
|
||||
<xsl:text>color:</xsl:text>
|
||||
<xsl:choose>
|
||||
<xsl:when test="attstr[@name='module' and @val='human'] or attnum[@name='points' and @val>0]">
|
||||
<xsl:value-of select="'bold'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'normal'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="TextColor">
|
||||
<xsl:choose>
|
||||
<xsl:when test="attstr[@name='module' and @val='human']">
|
||||
<xsl:when test="attstr[@name='module']/@val = 'human'">
|
||||
<xsl:value-of select="'red'"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="attnum[@name='points' and @val>0]">
|
||||
<xsl:when test="attnum[@name='points']/@val > 0">
|
||||
<xsl:value-of select="'blue'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'black'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:variable>
|
||||
|
||||
<!-- set format for the next row -->
|
||||
<tr>
|
||||
<xsl:attribute name="style">
|
||||
<xsl:text>font-weight:</xsl:text>
|
||||
<xsl:value-of select="$FontWeight"/>
|
||||
<xsl:text>; color:</xsl:text>
|
||||
<xsl:value-of select="$TextColor"/>
|
||||
</xsl:attribute>
|
||||
|
||||
<!-- Table content (row) -->
|
||||
<td> <xsl:value-of select="@name"/> </td>
|
||||
<td> <xsl:value-of select="attstr[@name='name']/@val"/> </td>
|
||||
<td> <xsl:value-of select="attnum[@name='points']/@val"/> </td>
|
||||
<td><xsl:value-of select="@name"/></td>
|
||||
<td><xsl:value-of select="attstr[@name='name']/@val"/></td>
|
||||
<td><xsl:value-of select="attnum[@name='points']/@val"/></td>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
|
||||
|
@ -251,6 +261,55 @@
|
|||
</p>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Show drivers positions over multiple race events -->
|
||||
<xsl:template name="Summary">
|
||||
<h3>Championship Summary</h3>
|
||||
<p>
|
||||
<table border="1">
|
||||
<!-- Table header -->
|
||||
<tr>
|
||||
<th>Driver/Track ->Rank</th>
|
||||
<!-- List all track names -->
|
||||
<xsl:for-each select="../section[@name!='Header' and @name!='Current' and @name!='Standings']">
|
||||
<th><xsl:value-of select="@name"/></th>
|
||||
</xsl:for-each>
|
||||
</tr>
|
||||
<xsl:for-each select="*/attstr[@name='name']">
|
||||
<xsl:variable name="DriverName" select="@val"/>
|
||||
<tr>
|
||||
<!-- choose an other format for human driver -->
|
||||
<xsl:if test="../attstr[@name='module']/@val = 'human'">
|
||||
<xsl:attribute name="style">
|
||||
<xsl:text>font-weight:bold</xsl:text>
|
||||
</xsl:attribute>
|
||||
</xsl:if>
|
||||
|
||||
<td><xsl:value-of select="$DriverName"/></td>
|
||||
<xsl:for-each select="//section[@name='Results']/section[@name='Race']/section[@name='Rank']/section/attstr[@name='name' and @val=$DriverName]">
|
||||
<td>
|
||||
<xsl:if test="../attnum[@name='points']/@val > 0">
|
||||
<xsl:attribute name="style">
|
||||
<xsl:text>color:</xsl:text>
|
||||
<xsl:choose>
|
||||
<!-- first place -->
|
||||
<xsl:when test="../@name = 1">
|
||||
<xsl:value-of select="'red'"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="'blue'"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
</xsl:if>
|
||||
<xsl:value-of select="../@name"/>
|
||||
</td>
|
||||
</xsl:for-each>
|
||||
</tr>
|
||||
</xsl:for-each>
|
||||
</table>
|
||||
</p>
|
||||
</xsl:template>
|
||||
|
||||
|
||||
<!-- Print values; speed and time will be formated. -->
|
||||
<xsl:template name="FormatedOutput">
|
||||
|
@ -261,20 +320,25 @@
|
|||
<!-- convert speed from m/s to km/h -->
|
||||
<xsl:value-of select="round(3.6*@val)"/>
|
||||
</xsl:when>
|
||||
<xsl:when test="@name = 'time' and $TimeDiff and ../../section[1]/attnum[@name='laps']/@val > ../attnum[@name='laps']/@val">
|
||||
<!-- when the winner overlaped this driver, show the difference of laps count instead of time -->
|
||||
<xsl:text>+</xsl:text>
|
||||
<xsl:variable name="LapsBehind" select="../../section[1]/attnum[@name='laps']/@val - ../attnum[@name='laps']/@val"/>
|
||||
<xsl:value-of select="$LapsBehind"/>
|
||||
<xsl:text> Lap</xsl:text>
|
||||
<xsl:if test="$LapsBehind > 1">s</xsl:if>
|
||||
</xsl:when>
|
||||
<xsl:when test="@name = 'time' and $TimeDiff and ../@name != 1">
|
||||
<!-- show the time difference to the winner with a plus sign -->
|
||||
<xsl:text>+</xsl:text>
|
||||
<xsl:call-template name="FormatTime">
|
||||
<xsl:with-param name="time" select="@val - ../../section[1]/attnum[@name='time']/@val"/>
|
||||
</xsl:call-template>
|
||||
<xsl:variable name="TotalLaps" select="../../section[1]/attnum[@name='laps']/@val"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$TotalLaps > ../attnum[@name='laps']/@val">
|
||||
<!-- when the winner overlapped this driver, show the lap count difference -->
|
||||
<xsl:text>+</xsl:text>
|
||||
<xsl:variable name="LapsBehind" select="$TotalLaps - ../attnum[@name='laps']/@val"/>
|
||||
<xsl:value-of select="$LapsBehind"/>
|
||||
<xsl:text> Lap</xsl:text>
|
||||
<xsl:if test="$LapsBehind > 1">s</xsl:if>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- show the time difference to the winner with a plus sign -->
|
||||
<xsl:text>+</xsl:text>
|
||||
<xsl:call-template name="FormatTime">
|
||||
<xsl:with-param name="time" select="@val - ../../section[1]/attnum[@name='time']/@val"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:when>
|
||||
<xsl:when test="contains(@name,'time')">
|
||||
<!-- print time -->
|
||||
|
@ -289,13 +353,22 @@
|
|||
</xsl:template>
|
||||
|
||||
|
||||
<!-- Converts positive time values from s to min:s. -->
|
||||
<!-- Converts positive time values from s to min:s or h min. -->
|
||||
<xsl:template name="FormatTime">
|
||||
<xsl:param name="time"/>
|
||||
<xsl:value-of select="floor($time div 60)"/>
|
||||
<xsl:text>:</xsl:text>
|
||||
<!-- (mod returns not exact values, therefore format to have 3 digits behind the decimal point) -->
|
||||
<xsl:value-of select="format-number(($time mod 60),'00.000')"/>
|
||||
<xsl:variable name="Minutes" select="floor($time div 60)"/>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$Minutes < 60">
|
||||
<xsl:value-of select="$Minutes"/>
|
||||
<xsl:text>:</xsl:text>
|
||||
<!-- (mod returns not exact values, therefore format to have 3 digits behind the decimal point) -->
|
||||
<xsl:value-of select="format-number(($time mod 60),'00.000')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="floor($Minutes div 60)"/>h
|
||||
<xsl:value-of select="$Minutes mod 60"/>min
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
Loading…
Reference in a new issue