Ticket #217: team_result_2.tmr.xsl

File team_result_2.tmr.xsl, 12.4 KB (added by Roberto Adinolfi, 10 years ago)
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
4<!--
5
6****************************************************************************************
7Participant list template 2.0 by SCDBob
8
9Changelog:
10-center align for competition name and title
11-red font for task status (i.e. Provisional)
12-table width 100%
13-other background color for team row
14
15*****************************************************************************************
16
17 -->
18
19  <!--  To see the input used for this xslt, check the "Create source.xml file
20        when creating report" menu item under the "Reports" menu in FsComp.
21        When checked a .source.xml file is created each time you create a report.
22        It shows the actual xml input to the xslt processor.
23        This is helpfull if you like to modify this file.
24  -->
25
26  <xsl:output method="html" encoding="utf-8" indent="yes" />
27
28  <!--  Set the decimal separator to be used (. or ,) when decimal data is displayed.
29        All decimal data in the source is with . and will be displayed with . unless
30        formated otherwise using format-number() function.
31  -->
32  <xsl:variable name="decimal_separator" select="','"/>
33  <xsl:decimal-format decimal-separator=',' grouping-separator=' ' />
34  <!-- note! make sure both above use same, ie either . or ,!! -->
35
36  <!--  All <xsl:param ... elements will show as a field in a report dialog in
37        FS when creating reports. This means you can define param elements here
38        with a default value and set the value from FS when creating report.
39        Some is used simply to display text at the top of the report (ie status),
40        others is used to filter the results (ie women_only, nation, ...).
41        If you add filter params you must of course also change the "filter"
42        definition below so that the filter params is applied.
43  -->
44  <xsl:param name="Heading">Team results</xsl:param>
45  <xsl:param name="status">Provisional</xsl:param>
46
47  <!-- list of param values. Should show list of all xsl:param elements specified above. -->
48  <xsl:template name="params_list" >
49    <h3>Param values used when creating the report</h3>
50    <table>
51      <thead>
52        <tr>
53          <th>param</th>
54          <th>value</th>
55        </tr>
56      </thead>
57      <tbody>
58        <tr>
59          <td>
60            Heading
61          </td>
62          <td>
63            <xsl:value-of select="$Heading"/>
64          </td>
65        </tr>
66        <tr>
67          <td>
68            status
69          </td>
70          <td>
71            <xsl:value-of select="$status"/>
72          </td>
73        </tr>
74      </tbody>
75    </table>
76  </xsl:template>
77
78  <!--  No of best tasks to use the sum of for each pilot.
79        Default is 'all' which is normally used.
80        Haven't got a clue on how to apply this to teams
81        so for now only 'all' is supported here.
82  -->
83  <xsl:variable name="top_x_tasks" select="'all'"/>
84
85  <!--  The node-set that this variable returns is what is used
86        to create the result list.
87        Here some of the params above is used.
88        NOTE: for team report it does not seem like there is any sort of filter
89        that makes sense to apply the FsTeamResults element, so we select all of it.
90  -->
91  <xsl:variable name="filter" select="
92      /Fs/FsCompetition/FsTeamResults[@top=$top_x_tasks]
93    "/>
94
95  <!--  Returns a ranking number based on the @points attribute in the element given by the item param.
96        Will give same ranking to elements with equal points.
97        NOTE! does NOT work when called inside a sorted node-list!!!
98  -->
99  <xsl:template name="calc_rank_from_points" >
100    <xsl:param name="item"/>
101    <xsl:param name="points"/>
102    <xsl:param name="sub" select="0"/>
103    <xsl:variable name="found" select="boolean($item/preceding-sibling::node()[1]/@points = $points)"/>
104    <xsl:choose>
105      <xsl:when test="$found = true()">
106        <xsl:call-template name="calc_rank_from_points">
107          <xsl:with-param name="item" select="$item/preceding-sibling::node()[1]"/>
108          <xsl:with-param name="points" select="$points"/>
109          <xsl:with-param name="sub" select="$sub+1"/>
110        </xsl:call-template>
111      </xsl:when>
112      <xsl:otherwise>
113        <xsl:value-of select="position()-$sub"/>
114      </xsl:otherwise>
115    </xsl:choose>
116  </xsl:template>
117
118  <!-- list of tasks -->
119  <xsl:template name="FsTask_list">
120    <table>
121      <thead>
122        <tr>
123          <th>Task</th>
124          <th>Date</th>
125          <th>Distance</th>
126          <th></th>
127        </tr>
128      </thead>
129      <tbody>
130        <xsl:for-each select="/Fs/FsCompetition/FsTeamResults[$top_x_tasks]/FsTeam[1]/FsParticipant[1]/FsTask">
131          <xsl:variable name="task_id" select="@id"/>
132          <xsl:variable name="es" select="/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/FsTaskDefinition/@es"/>
133          <xsl:variable name="no_of_startgates" select="count(/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/FsTaskDefinition/FsStartGate)"/>
134          <xsl:variable name="task_distance" select="/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/FsTaskScoreParams/@task_distance"/>
135          <tr>
136            <td>
137              T<xsl:value-of select="position()"/>
138              <xsl:text>&#160;</xsl:text>
139              <xsl:value-of select="/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/@name"/>
140            </td>
141            <td>
142              <xsl:value-of select="translate(substring(/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/FsTaskDefinition/FsTurnpoint[1]/@open, 1, 16), 'T', ' ')"/>
143              <xsl:text>&#160;&#160;</xsl:text>
144              <xsl:value-of select="@name"/>
145            </td>
146            <td>
147              <xsl:if test="$es">
148                <xsl:text>&#160;</xsl:text>
149                <xsl:value-of select="format-number($task_distance, concat('#0', $decimal_separator, '0'))"/>
150                <xsl:text> km</xsl:text>
151              </xsl:if>
152            </td>
153            <td>
154              <xsl:choose>
155                <xsl:when test="$es and $no_of_startgates > 0">
156                  <xsl:text>Race to Goal with </xsl:text>
157                  <xsl:value-of select="$no_of_startgates"/>
158                  <xsl:text> startgate(s)</xsl:text>
159                </xsl:when>
160                <xsl:when test="$es and $no_of_startgates = 0">
161                  <xsl:text>Elapsed time</xsl:text>
162                </xsl:when>
163                <xsl:otherwise>
164                  <xsl:text>Open Distance</xsl:text>
165                </xsl:otherwise>
166              </xsl:choose>
167            </td>
168          </tr>
169        </xsl:for-each>
170      </tbody>
171    </table>
172  </xsl:template>
173
174  <!-- record template, used for each team-member -->
175  <xsl:template name="record">
176    <xsl:variable name="pilot_id" select="@id"/>
177    <tr>
178      <td>
179      </td>
180      <td>
181        <xsl:value-of select="@id"/>
182      </td>
183      <td>
184        <xsl:value-of select="/Fs/FsCompetition/FsParticipants/FsParticipant[@id=$pilot_id]/@name"/>
185      </td>
186      <td>
187        <xsl:choose>
188          <xsl:when test="/Fs/FsCompetition/FsParticipants/FsParticipant[@id=$pilot_id]/@female=1">F</xsl:when>
189          <xsl:otherwise>M</xsl:otherwise>
190        </xsl:choose>
191      </td>
192      <td>
193        <xsl:value-of select="/Fs/FsCompetition/FsParticipants/FsParticipant[@id=$pilot_id]/@nat_code_3166_a3"/>
194      </td>
195      <td>
196        <xsl:value-of select="/Fs/FsCompetition/FsParticipants/FsParticipant[@id=$pilot_id]/@glider"/>
197      </td>
198      <td>
199        <xsl:value-of select="/Fs/FsCompetition/FsParticipants/FsParticipant[@id=$pilot_id]/@sponsor"/>
200      </td>
201      <xsl:for-each select="FsTask">
202        <xsl:variable name="task_id" select="@id"/>
203        <xsl:choose>
204          <xsl:when test="@counts='1'">
205            <td style="text-align: right">
206              <xsl:value-of select="/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/FsParticipants/FsParticipant[@id=$pilot_id]/FsResult/@points"/>
207            </td>
208          </xsl:when>
209          <xsl:otherwise>
210            <td style="text-align: right; text-decoration: line-through;">
211              <xsl:value-of select="/Fs/FsCompetition/FsTasks/FsTask[@id=$task_id]/FsParticipants/FsParticipant[@id=$pilot_id]/FsResult/@points"/>
212            </td>
213          </xsl:otherwise>
214        </xsl:choose>
215      </xsl:for-each>
216      <td>
217      </td>
218    </tr>
219  </xsl:template>
220
221  <!-- Main template. This is where it all starts. -->
222  <xsl:template match="/">
223    <html>
224      <head>
225        <style>
226          tr:hover {background: yellow;}
227          body {
228          font-family: Verdana, Arial, Helvetica, sans-serif;
229          font-size: xx-small;
230          }
231          table
232          {
233          border:solid 1px gray;
234          border-collapse:collapse;
235          font-size: xx-small;
236          }
237          td
238          {
239          border:solid 1px gray;
240          vertical-align:top;
241          padding:5px;
242          }
243          th
244          {
245          border:solid 1px gray;
246          vertical-align:center;
247          }
248        </style>
249      </head>
250      <body>
251        <div style="width:100%;font-size: xx-small;text-align:right;" >
252          <i>
253            Report created: <xsl:value-of select="/Fs/FsCompetition/FsTeamResults[$top_x_tasks]/@ts"/>
254          </i>
255        </div>
256                <div style="text-align:center;">
257        <h1>
258          <xsl:value-of select="/Fs/FsCompetition/@name"/>
259        </h1>
260        <p style="font-size:xx-small">
261          <xsl:value-of select="/Fs/FsCompetition/@from"/> to <xsl:value-of select="/Fs/FsCompetition/@to"/>
262        </p>
263        <h2>
264          <xsl:value-of select="$Heading"/>
265        </h2>
266        <p>
267          <strong style="color:red;"><xsl:value-of select="$status"/></strong>
268        </p>
269                </div>
270        <xsl:call-template name="FsTask_list"></xsl:call-template>
271        <br/>
272        <table style="width:100%">
273          <thead>
274            <tr>
275              <th>#</th>
276              <th>Id</th>
277              <th>Name</th>
278              <th></th>
279              <th>Nat</th>
280              <th>Glider</th>
281              <th>Sponsor</th>
282              <xsl:for-each select="/Fs/FsCompetition/FsTeamResults[$top_x_tasks]/FsTeam[1]/FsParticipant[1]/FsTask">
283                <th>
284                  <xsl:text>T </xsl:text>
285                  <xsl:value-of select="position()"/>
286                </th>
287              </xsl:for-each>
288              <th>Total</th>
289            </tr>
290          </thead>
291
292          <!-- for each team sorted ascending on rank -->
293          <xsl:for-each select="$filter/FsTeam">
294            <xsl:sort select="@points" data-type="number" order="descending"/>
295            <!-- team row -->
296            <tr style="background-color:#E0E0E0;font-weight:bold">
297              <td>
298                <!--xsl:value-of select="@rank"/ -->
299                <xsl:call-template name="calc_rank_from_points">
300                  <xsl:with-param name="item" select="."/>
301                  <xsl:with-param name="points" select="@points"/>
302                </xsl:call-template>
303              </td>
304              <td>
305              </td>
306              <td>
307                  <xsl:value-of select="@name"/>
308              </td>
309              <td>
310              </td>
311              <td>
312              </td>
313              <td>
314              </td>
315              <td>
316              </td>
317              <!-- an empty cell for each task in team row -->
318              <xsl:for-each select="/Fs/FsCompetition/FsTeamResults[$top_x_tasks]/FsTeam[1]/FsParticipant[1]/FsTask">
319                <td></td>
320              </xsl:for-each>
321              <td align="right">
322                <xsl:value-of select="@points"/>
323              </td>
324            </tr>
325
326            <!-- for each team-member -->
327            <!-- participant rows -->
328            <xsl:for-each select="FsParticipant">
329              <xsl:call-template name="record"/>
330            </xsl:for-each>
331          </xsl:for-each>
332        </table>
333        <div>
334          <xsl:call-template name="params_list"/>
335        </div>
336                <p>
337                        <div style="text-align:center; font-size:xxxx-small;">
338                                Competition scored with <a href="http://fs.fai.org/">FS</a><br/>
339                                Template powered by SCDBob
340                        </div>
341                </p>
342      </body>
343    </html>
344  </xsl:template>
345
346</xsl:stylesheet>