-
Notifications
You must be signed in to change notification settings - Fork 4
/
mos-json-opt.xsl
151 lines (144 loc) · 5.21 KB
/
mos-json-opt.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?xml version="1.0" encoding="UTF-8"?>
<!--
| ============================================================================
|
| Converts MOSMIX-KML to JSON
|
| Used Variables:
|
| - station: the station id
| - title: title in long form
| - titleShort: title in short form
| - lon: longitude of station location
| - lat: latitude of station location
|
| ============================================================================
|
| Author: Michael Buchfink
|
| ============================================================================
|
| Last updated: 19.03.2018
|
| ============================================================================
|
| Licensed to the Apache Software Foundation (ASF) under one
| or more contributor license agreements. See the NOTICE file
| distributed with this work for additional information
| regarding copyright ownership. The ASF licenses this file
| to you under the Apache License, Version 2.0 (the
| "License"); you may not use this file except in compliance
| with the License. You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing,
| software distributed under the License is distributed on an
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
| KIND, either express or implied. See the License for the
| specific language governing permissions and limitations
| under the License.
|
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dwd="https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd"
xmlns:kml="http://www.opengis.net/kml/2.2">
<xsl:output method="text" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="kml:Document">
<xsl:text>{</xsl:text>
<xsl:apply-templates />
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="kml:ExtendedData">
<xsl:text>"issuer": "</xsl:text>
<xsl:value-of select="dwd:ProductDefinition/dwd:Issuer" />
<xsl:text>"</xsl:text>
<xsl:text>, "productId": "</xsl:text>
<xsl:value-of select="dwd:ProductDefinition/dwd:ProductID" />
<xsl:text>"</xsl:text>
<xsl:text>, "generatingProcess": "</xsl:text>
<xsl:value-of select="dwd:ProductDefinition/dwd:GeneratingProcess" />
<xsl:text>"</xsl:text>
<xsl:apply-templates select="dwd:ProductDefinition/dwd:ForecastTimeSteps" />
</xsl:template>
<xsl:template match="dwd:ForecastTimeSteps">
<xsl:text>, "timeSteps": [</xsl:text>
<xsl:for-each select="dwd:TimeStep">
<xsl:text>"</xsl:text>
<xsl:value-of select="." />
<xsl:text>"</xsl:text>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="kml:Placemark">
<xsl:if test="kml:name=$station">
<xsl:text>, "station": {</xsl:text>
<xsl:text>"name": "</xsl:text>
<xsl:value-of select="$station" />
<xsl:text>"</xsl:text>
<xsl:text>, "description": "</xsl:text>
<xsl:value-of select="kml:description" />
<xsl:text>"</xsl:text>
<xsl:text>, "title": "</xsl:text>
<xsl:value-of select="$title" />
<xsl:text>"</xsl:text>
<xsl:text>, "titleShort": "</xsl:text>
<xsl:value-of select="$titleShort" />
<xsl:text>"</xsl:text>
<xsl:text>, "coordinates": [</xsl:text>
<xsl:value-of select="kml:Point/kml:coordinates" />
<xsl:text>]</xsl:text>
<xsl:for-each select="kml:ExtendedData/dwd:Forecast">
<xsl:if test="
@dwd:elementName = 'TTT' or
@dwd:elementName = 'Td' or
@dwd:elementName = 'PPPP' or
@dwd:elementName = 'RR1c' or
@dwd:elementName = 'FF' or
@dwd:elementName = 'DD' or
@dwd:elementName = 'SunD1' or
@dwd:elementName = 'Neff' or
@dwd:elementName = 'ww'
">
<xsl:text>, "</xsl:text>
<xsl:value-of select="@dwd:elementName" />
<xsl:text>": [</xsl:text>
<xsl:attribute name="dwd:elementName"><xsl:value-of
select="@dwd:elementName" /></xsl:attribute>
<xsl:call-template name="format">
<xsl:with-param name="text" select="normalize-space()" />
</xsl:call-template>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="format">
<xsl:param name="text" />
<xsl:variable name="replace" select="' '" />
<xsl:variable name="with" select="','" />
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:text>"</xsl:text>
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:text>"</xsl:text>
<xsl:value-of select="$with" />
<xsl:call-template name="format">
<xsl:with-param name="text"
select="substring-after($text,$replace)" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>"</xsl:text>
<xsl:value-of select="$text" />
<xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>