comparison flys-artifacts/contrib/fixoverview2html.xsl @ 2565:72f77b2210c2

FixingsOverview: Added XSL transformation which directly converts the output of the fixings overview service into an HTML representation. flys-artifacts/trunk@4091 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 21 Feb 2012 18:22:06 +0000
parents
children 7d163c2c6e6d
comparison
equal deleted inserted replaced
2564:3f038d54bc87 2565:72f77b2210c2
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
8 <xsl:template name="percent">
9 <xsl:param name="sector"/>
10 <xsl:variable name="rfrom" select="number(/fixings/river/@from)"/>
11 <xsl:variable name="rto" select="number(/fixings/river/@to)"/>
12 <xsl:variable name="rlength" select="$rto - $rfrom"/>
13
14 <xsl:variable name="sfrom" select="number($sector/@from)"/>
15 <xsl:variable name="sto" select="number($sector/@to)"/>
16 <xsl:variable name="slength" select="$sto - $sfrom"/>
17 <xsl:value-of select="100.0 * ($slength div $rlength)"/>
18 </xsl:template>
19
20 <xsl:template name="emit-gap">
21 <xsl:param name="sector"/>
22 <xsl:variable name="preds" select="$sector/preceding-sibling::sector"/>
23 <xsl:variable name="num-preds" select="count($preds)"/>
24 <xsl:variable name="glength">
25 <xsl:choose>
26 <xsl:when test="$num-preds &lt; 1">
27 <xsl:variable name="rfrom" select="number(/fixings/river/@from)"/>
28 <xsl:value-of select="number($sector/@from) - $rfrom"/>
29 </xsl:when>
30 <xsl:otherwise>
31 <xsl:variable name="bend" select="number($preds[last()]/@to)"/>
32 <xsl:value-of select="number($sector/@from) - $bend"/>
33 </xsl:otherwise>
34 </xsl:choose>
35 </xsl:variable>
36 <xsl:choose>
37 <xsl:when test="number($glength) &lt; 0.05 "/>
38 <xsl:otherwise>
39 <div>
40 <xsl:attribute name="style">
41 <xsl:text>width:</xsl:text>
42 <xsl:variable name="rfrom" select="number(/fixings/river/@from)"/>
43 <xsl:variable name="rto" select="number(/fixings/river/@to)"/>
44 <xsl:variable name="rlength" select="$rto - $rfrom"/>
45 <xsl:value-of select="100.0 * ($glength div $rlength)"/>
46 <xsl:text>%;float:left</xsl:text>
47 </xsl:attribute>
48 <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
49 </div>
50 </xsl:otherwise>
51 </xsl:choose>
52 </xsl:template>
53
54 <xsl:template match="sector" mode="sectors">
55 <xsl:call-template name="emit-gap">
56 <xsl:with-param name="sector" select="."/>
57 </xsl:call-template>
58 <div>
59 <xsl:attribute name="style">
60 <xsl:text>background:</xsl:text>
61 <xsl:choose>
62 <xsl:when test="@class = '0'">green</xsl:when>
63 <xsl:when test="@class = '1'">blue</xsl:when>
64 <xsl:when test="@class = '2'">magenta</xsl:when>
65 <xsl:when test="@class = '3'">red</xsl:when>
66 <xsl:otherwise>black</xsl:otherwise>
67 </xsl:choose>
68 <xsl:text>;width:</xsl:text>
69 <xsl:call-template name="percent">
70 <xsl:with-param name="sector" select="."/>
71 </xsl:call-template>
72 <xsl:text>%</xsl:text>
73 <xsl:text>;float:left</xsl:text>
74 </xsl:attribute>
75 <xsl:attribute name="title">
76 <xsl:text>km </xsl:text>
77 <xsl:value-of select="@from"/>
78 <xsl:text> - </xsl:text>
79 <xsl:value-of select="@to"/>
80 </xsl:attribute>
81 <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
82 </div>
83 </xsl:template>
84
85 <xsl:template match="event">
86 <tr>
87 <td>
88 <xsl:apply-templates mode="sectors"/>
89 </td>
90 <td align="center">
91 <xsl:attribute name="title"><xsl:value-of select="@name"/></xsl:attribute>
92 <xsl:value-of select="@date"/>
93 </td>
94 </tr>
95 </xsl:template>
96
97 <xsl:template match="events">
98 <table width="95%" border="1" cellspacing="0" cellpadding="0">
99 <colgroup>
100 <col width="85%"/>
101 <col width="15%"/>
102 </colgroup>
103 <xsl:apply-templates/>
104 </table>
105 </xsl:template>
106
107 <xsl:template match="/">
108 <html>
109 <head>
110 <title>Fixierungen:</title>
111 </head>
112 <body>
113 <xsl:apply-templates/>
114 </body>
115 </html>
116 </xsl:template>
117
118 <xsl:template match="text()"/>
119 <xsl:template match="text()" mode="sectors"/>
120
121 </xsl:stylesheet>

http://dive4elements.wald.intevation.org