Mercurial > dive4elements > river
comparison flys-artifacts/contrib/fixoverview2html.xsl @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | c3fb41e73ffb |
children |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 <?xml version="1.0" encoding="UTF-8"?> | |
2 <xsl:stylesheet | |
3 version="1.0" | |
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
5 | |
6 <xsl:output method="xml" encoding="UTF-8" | |
7 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" | |
8 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/> | |
9 | |
10 <xsl:param name="project-uuid">de3f3307-3429-4ff9-8f43-3fb2fcf21b27</xsl:param> | |
11 <xsl:param name="render-checkboxes" select="true()"/> | |
12 <xsl:param name="callback"/> | |
13 | |
14 <xsl:param name="locale">de</xsl:param> | |
15 | |
16 <xsl:decimal-format name="de" decimal-separator=',' grouping-separator='.'/> | |
17 <xsl:decimal-format name="en" decimal-separator='.' grouping-separator=','/> | |
18 | |
19 <!-- XXX: This kind of i18n is cheesy. | |
20 It should be better done in an external resource. --> | |
21 | |
22 <xsl:variable name="km-pattern"> | |
23 <xsl:choose> | |
24 <xsl:when test="$locale = 'de'">0,##</xsl:when> | |
25 <xsl:otherwise>0.##</xsl:otherwise> | |
26 </xsl:choose> | |
27 </xsl:variable> | |
28 | |
29 <xsl:variable name="i18n-event"> | |
30 <xsl:choose> | |
31 <xsl:when test="$locale = 'de'">Ereignis</xsl:when> | |
32 <xsl:otherwise>Event</xsl:otherwise> | |
33 </xsl:choose> | |
34 </xsl:variable> | |
35 | |
36 <xsl:variable name="i18n-legend"> | |
37 <xsl:choose> | |
38 <xsl:when test="$locale = 'de'">Legende</xsl:when> | |
39 <xsl:otherwise>Caption</xsl:otherwise> | |
40 </xsl:choose> | |
41 </xsl:variable> | |
42 | |
43 <xsl:variable name="i18n-color"> | |
44 <xsl:choose> | |
45 <xsl:when test="$locale = 'de'">Farbe</xsl:when> | |
46 <xsl:otherwise>Color</xsl:otherwise> | |
47 </xsl:choose> | |
48 </xsl:variable> | |
49 | |
50 <xsl:variable name="i18n-meaning"> | |
51 <xsl:choose> | |
52 <xsl:when test="$locale = 'de'">Bedeutung</xsl:when> | |
53 <xsl:otherwise>Meaning</xsl:otherwise> | |
54 </xsl:choose> | |
55 </xsl:variable> | |
56 | |
57 <xsl:variable name="i18n-around-mnq"> | |
58 <xsl:choose> | |
59 <xsl:when test="$locale = 'de'">um MNQ</xsl:when> | |
60 <xsl:otherwise>around MNQ</xsl:otherwise> | |
61 </xsl:choose> | |
62 </xsl:variable> | |
63 | |
64 <xsl:variable name="i18n-around-mq"> | |
65 <xsl:choose> | |
66 <xsl:when test="$locale = 'de'">um MQ</xsl:when> | |
67 <xsl:otherwise>around MQ</xsl:otherwise> | |
68 </xsl:choose> | |
69 </xsl:variable> | |
70 | |
71 <xsl:variable name="i18n-around-mhq"> | |
72 <xsl:choose> | |
73 <xsl:when test="$locale = 'de'">um MHQ</xsl:when> | |
74 <xsl:otherwise>around MHQ</xsl:otherwise> | |
75 </xsl:choose> | |
76 </xsl:variable> | |
77 | |
78 <xsl:variable name="i18n-above-hq5"> | |
79 <xsl:choose> | |
80 <xsl:when test="$locale = 'de'">über HQ5</xsl:when> | |
81 <xsl:otherwise>above HQ5</xsl:otherwise> | |
82 </xsl:choose> | |
83 </xsl:variable> | |
84 | |
85 <!-- TODO: Format dates according locale. --> | |
86 | |
87 <xsl:template match="@*" mode="min"> | |
88 <xsl:if test="position() = 1"> | |
89 <xsl:value-of select="number(.)"/> | |
90 </xsl:if> | |
91 </xsl:template> | |
92 | |
93 <xsl:template match="@*" mode="max"> | |
94 <xsl:if test="position() = last()"> | |
95 <xsl:value-of select="number(.)"/> | |
96 </xsl:if> | |
97 </xsl:template> | |
98 | |
99 <xsl:variable name="global-min"> | |
100 <xsl:choose> | |
101 <xsl:when test="count(/fixings/events/event/sector) > 0"> | |
102 <xsl:apply-templates mode="min" select="/fixings/events/event/sector/@from"> | |
103 <xsl:sort data-type="number" select="."/> | |
104 </xsl:apply-templates> | |
105 </xsl:when> | |
106 <xsl:otherwise> | |
107 <xsl:value-of select="number(/fixings/river/@from)"/> | |
108 </xsl:otherwise> | |
109 </xsl:choose> | |
110 </xsl:variable> | |
111 | |
112 <xsl:variable name="global-max"> | |
113 <xsl:choose> | |
114 <xsl:when test="count(/fixings/events/event/sector) > 0"> | |
115 <xsl:apply-templates mode="max" select="/fixings/events/event/sector/@to"> | |
116 <xsl:sort data-type="number" select="."/> | |
117 </xsl:apply-templates> | |
118 </xsl:when> | |
119 <xsl:otherwise> | |
120 <xsl:value-of select="number(/fixings/river/@to)"/> | |
121 </xsl:otherwise> | |
122 </xsl:choose> | |
123 </xsl:variable> | |
124 | |
125 <xsl:template name="percent"> | |
126 <xsl:param name="sector"/> | |
127 | |
128 <xsl:variable name="start"> | |
129 <xsl:choose> | |
130 <xsl:when test="number($sector/@from) < $global-min"> | |
131 <xsl:value-of select="$global-min"/> | |
132 </xsl:when> | |
133 <xsl:otherwise> | |
134 <xsl:value-of select="number($sector/@from)"/> | |
135 </xsl:otherwise> | |
136 </xsl:choose> | |
137 </xsl:variable> | |
138 | |
139 <xsl:variable name="end"> | |
140 <xsl:choose> | |
141 <xsl:when test="number($sector/@to) > $global-max"> | |
142 <xsl:value-of select="$global-max"/> | |
143 </xsl:when> | |
144 <xsl:otherwise> | |
145 <xsl:value-of select="number($sector/@to)"/> | |
146 </xsl:otherwise> | |
147 </xsl:choose> | |
148 </xsl:variable> | |
149 | |
150 <xsl:choose> | |
151 <xsl:when test="$end < $start"> | |
152 <xsl:value-of select="number(0)"/> | |
153 </xsl:when> | |
154 <xsl:otherwise> | |
155 <xsl:value-of select="100.0 * (($end - $start) div ($global-max - $global-min))"/> | |
156 </xsl:otherwise> | |
157 </xsl:choose> | |
158 </xsl:template> | |
159 | |
160 <xsl:template name="emit-gap-gauge"> | |
161 <xsl:param name="gauge"/> | |
162 <xsl:call-template name="internal-emit-gap"> | |
163 <xsl:with-param name="sector" select="$gauge"/> | |
164 <xsl:with-param name="preds" select="$gauge/preceding-sibling::gauge"/> | |
165 </xsl:call-template> | |
166 </xsl:template> | |
167 | |
168 <xsl:template name="emit-gap"> | |
169 <xsl:param name="sector"/> | |
170 <xsl:call-template name="internal-emit-gap"> | |
171 <xsl:with-param name="sector" select="$sector"/> | |
172 <xsl:with-param name="preds" select="$sector/preceding-sibling::sector"/> | |
173 </xsl:call-template> | |
174 </xsl:template> | |
175 | |
176 <xsl:template name="internal-emit-gap"> | |
177 <xsl:param name="sector"/> | |
178 <xsl:param name="preds"/> | |
179 | |
180 <xsl:variable name="start"> | |
181 <xsl:choose> | |
182 <xsl:when test="number($sector/@from) < $global-min"> | |
183 <xsl:value-of select="$global-min"/> | |
184 </xsl:when> | |
185 <xsl:otherwise> | |
186 <xsl:value-of select="$sector/@from"/> | |
187 </xsl:otherwise> | |
188 </xsl:choose> | |
189 </xsl:variable> | |
190 | |
191 <xsl:if test="$start < $global-max"> | |
192 <xsl:variable name="num-preds" select="count($preds)"/> | |
193 <xsl:variable name="prev-end"> | |
194 <xsl:choose> | |
195 <xsl:when test="count($preds) < 1"> | |
196 <xsl:value-of select="$global-min"/> | |
197 </xsl:when> | |
198 <xsl:otherwise> | |
199 <xsl:value-of select="number($preds[last()]/@to)"/> | |
200 </xsl:otherwise> | |
201 </xsl:choose> | |
202 </xsl:variable> | |
203 | |
204 <xsl:if test="$prev-end < $global-max"> | |
205 <xsl:variable name="gap-len" select="$start - $prev-end"/> | |
206 <xsl:if test="$gap-len > 0.005"> | |
207 <div> | |
208 <xsl:attribute name="style"> | |
209 <xsl:text>width:</xsl:text> | |
210 <xsl:value-of select="100.0 * ($gap-len div ($global-max - $global-min))"/> | |
211 <xsl:text>%;float:left</xsl:text> | |
212 </xsl:attribute> | |
213 <xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text> | |
214 </div> | |
215 </xsl:if> | |
216 </xsl:if> | |
217 </xsl:if> | |
218 </xsl:template> | |
219 | |
220 <xsl:template match="sector" mode="sectors"> | |
221 <xsl:call-template name="emit-gap"> | |
222 <xsl:with-param name="sector" select="."/> | |
223 </xsl:call-template> | |
224 <div> | |
225 <xsl:attribute name="style"> | |
226 <xsl:text>background:</xsl:text> | |
227 <xsl:choose> | |
228 <xsl:when test="@class = '0'">green</xsl:when> | |
229 <xsl:when test="@class = '1'">blue</xsl:when> | |
230 <xsl:when test="@class = '2'">magenta</xsl:when> | |
231 <xsl:when test="@class = '3'">red</xsl:when> | |
232 <xsl:otherwise>black</xsl:otherwise> | |
233 </xsl:choose> | |
234 <xsl:text>;width:</xsl:text> | |
235 <xsl:call-template name="percent"> | |
236 <xsl:with-param name="sector" select="."/> | |
237 </xsl:call-template> | |
238 <xsl:text>%</xsl:text> | |
239 <xsl:text>;float:left</xsl:text> | |
240 </xsl:attribute> | |
241 <xsl:attribute name="title"> | |
242 <xsl:text>km </xsl:text> | |
243 <xsl:value-of select="format-number(@from, $km-pattern, $locale)"/> | |
244 <xsl:text> - </xsl:text> | |
245 <xsl:value-of select="format-number(@to, $km-pattern, $locale)"/> | |
246 <xsl:choose> | |
247 <xsl:when test="@class = '0'"> / Q <xsl:value-of select="$i18n-around-mnq"/></xsl:when> | |
248 <xsl:when test="@class = '1'"> / Q <xsl:value-of select="$i18n-around-mq"/></xsl:when> | |
249 <xsl:when test="@class = '2'"> / Q <xsl:value-of select="$i18n-around-mhq"/></xsl:when> | |
250 <xsl:when test="@class = '3'"> / Q <xsl:value-of select="$i18n-above-hq5"/></xsl:when> | |
251 </xsl:choose> | |
252 </xsl:attribute> | |
253 <xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text> | |
254 </div> | |
255 </xsl:template> | |
256 | |
257 <xsl:template match="event"> | |
258 <tr id="{@cid}"> | |
259 <xsl:if test="$render-checkboxes"> | |
260 <td> | |
261 <input type="checkbox" name="{$project-uuid}:{@cid}" checked="true" onclick="{$callback}"/> | |
262 </td> | |
263 </xsl:if> | |
264 <td> | |
265 <xsl:apply-templates mode="sectors"/> | |
266 </td> | |
267 <td align="center"> | |
268 <xsl:attribute name="title"><xsl:value-of select="@description"/></xsl:attribute> | |
269 <xsl:value-of select="@date"/> | |
270 </td> | |
271 </tr> | |
272 </xsl:template> | |
273 | |
274 <xsl:template match="gauge" mode="gauges"> | |
275 <xsl:call-template name="emit-gap-gauge"> | |
276 <xsl:with-param name="gauge" select="."/> | |
277 </xsl:call-template> | |
278 <div> | |
279 <xsl:variable name="start"> | |
280 <xsl:choose> | |
281 <xsl:when test="number(@from) < $global-min"> | |
282 <xsl:value-of select="$global-min"/> | |
283 </xsl:when> | |
284 <xsl:otherwise> | |
285 <xsl:value-of select="number(@from)"/> | |
286 </xsl:otherwise> | |
287 </xsl:choose> | |
288 </xsl:variable> | |
289 | |
290 <xsl:variable name="end"> | |
291 <xsl:choose> | |
292 <xsl:when test="number(@to) > $global-max"> | |
293 <xsl:value-of select="$global-max"/> | |
294 </xsl:when> | |
295 <xsl:otherwise> | |
296 <xsl:value-of select="number(@to)"/> | |
297 </xsl:otherwise> | |
298 </xsl:choose> | |
299 </xsl:variable> | |
300 | |
301 <xsl:attribute name="style"> | |
302 <xsl:text>overflow:hidden;background:</xsl:text> | |
303 <xsl:choose> | |
304 <xsl:when test="(count(preceding::*) mod 2) = 0">#ada96e</xsl:when> | |
305 <xsl:otherwise>silver</xsl:otherwise> | |
306 </xsl:choose> | |
307 <xsl:text>;width:</xsl:text> | |
308 <xsl:call-template name="percent"> | |
309 <xsl:with-param name="sector" select="."/> | |
310 </xsl:call-template> | |
311 <xsl:text>%</xsl:text> | |
312 <xsl:text>;float:left</xsl:text> | |
313 </xsl:attribute> | |
314 <xsl:attribute name="title"> | |
315 <xsl:value-of select="@name"/> | |
316 <xsl:text>: km </xsl:text> | |
317 <xsl:value-of select="format-number($start, $km-pattern, $locale)"/> | |
318 <xsl:text> - </xsl:text> | |
319 <xsl:value-of select="format-number($end, $km-pattern, $locale)"/> | |
320 </xsl:attribute> | |
321 <nobr><xsl:value-of select="@name"/></nobr> | |
322 </div> | |
323 </xsl:template> | |
324 | |
325 <xsl:template match="events"> | |
326 <table width="97%" border="1" cellspacing="0" cellpadding="0" | |
327 style="font-size: 10pt;font-family:Arial;Verdana,sans-serif"> | |
328 <colgroup> | |
329 <xsl:if test="$render-checkboxes"> | |
330 <col width="20px"/> | |
331 </xsl:if> | |
332 <col width="*"/> | |
333 <col width="75px"/> | |
334 </colgroup> | |
335 <tr> | |
336 <xsl:if test="$render-checkboxes"> | |
337 <th> </th> | |
338 </xsl:if> | |
339 <th><xsl:apply-templates mode="gauges" select="/fixings/gauges"/></th> | |
340 <th><xsl:value-of select="$i18n-event"/></th> | |
341 </tr> | |
342 <xsl:apply-templates/> | |
343 </table> | |
344 </xsl:template> | |
345 | |
346 <xsl:template match="/"> | |
347 <html> | |
348 <head> | |
349 <title>Fixierungen:</title> | |
350 </head> | |
351 <body> | |
352 <xsl:apply-templates/> | |
353 <hr/> | |
354 <table border="1" cellspacing="0" cellpadding="0"> | |
355 <caption><xsl:value-of select="$i18n-legend"/></caption> | |
356 <tr> | |
357 <th><xsl:value-of select="$i18n-color"/></th> | |
358 <th colspan="2"><xsl:value-of select="$i18n-meaning"/></th> | |
359 </tr> | |
360 <xsl:if test="count(/fixings/events/event/sector[@class = '0']) > 0"> | |
361 <tr> | |
362 <td style="background: green"> </td> | |
363 <td><xsl:value-of select="$i18n-around-mnq"/></td> | |
364 <td>Q ∈ [0, (MNQ+MQ)/2)</td> | |
365 </tr> | |
366 </xsl:if> | |
367 <xsl:if test="count(/fixings/events/event/sector[@class = '1']) > 0"> | |
368 <tr> | |
369 <td style="background: blue"> </td> | |
370 <td><xsl:value-of select="$i18n-around-mq"/></td> | |
371 <td>Q ∈ [(MNQ+MQ)/2, (MQ+MHQ)/2)</td> | |
372 </tr> | |
373 </xsl:if> | |
374 <xsl:if test="count(/fixings/events/event/sector[@class = '2']) > 0"> | |
375 <tr> | |
376 <td style="background: magenta"> </td> | |
377 <td><xsl:value-of select="$i18n-around-mhq"/></td> | |
378 <td>Q ∈ [(MQ+MHQ)/2, HQ5)</td> | |
379 </tr> | |
380 </xsl:if> | |
381 <xsl:if test="count(/fixings/events/event/sector[@class = '3']) > 0"> | |
382 <tr> | |
383 <td style="background: red"> </td> | |
384 <td><xsl:value-of select="$i18n-above-hq5"/></td> | |
385 <td>Q ∈ [HQ5, ∞)</td> | |
386 </tr> | |
387 </xsl:if> | |
388 </table> | |
389 </body> | |
390 </html> | |
391 </xsl:template> | |
392 | |
393 <xsl:template match="text()"/> | |
394 <xsl:template match="text()" mode="sectors"/> | |
395 <xsl:template match="text()" mode="gauges"/> | |
396 | |
397 </xsl:stylesheet> |