Debian Codegraph @

res/res_geolocation/pidf_to_eprofile.xslt

raw symbols SCIP
1 <?xml version="1.0"?>
2 <xsl:stylesheet version="1.0"
3 xmlns:ca="urn:ietf:params:xml:ns:pidf:geopriv10:civicAddr"
4 xmlns:def="urn:ietf:params:xml:ns:pidf"
5 xmlns:dm="urn:ietf:params:xml:ns:pidf:data-model"
6 xmlns:fn="http://www.w3.org/2005/xpath-functions"
7 xmlns:gbp="urn:ietf:params:xml:ns:pidf:geopriv10:basicPolicy"
8 xmlns:gml="http://www.opengis.net/gml"
9 xmlns:gp="urn:ietf:params:xml:ns:pidf:geopriv10"
10 xmlns:gs="http://www.opengis.net/pidflo/1.0"
11 xmlns:con="urn:ietf:params:xml:ns:geopriv:conf"
12 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
13
14
15 <!--
16 The whole purpose of this stylesheet is to convert a PIDF-LO document into a simple,
17 common XML document that is easily parsable by geoloc_eprofile into an eprofile.
18
19 For example:
20
21 <presence>
22 <device>
23 <location-info format="GML">shape="Point", crs="2d", pos="38.456 -105.678"</location-info>
24 <usage-rules>retransmission-allowed=no</usage-rules>
25 <method>GPS</method>
26 </device>
27 </presence>
28
29 WARNING: Don't mess with this stylesheet before brushing up your
30 XPath and XSLT expertise.
31 -->
32
33
34 <!--
35 All of the namespaces that could be in the incoming PIDF-LO document
36 have to be declared above. All matching is done based on the URI, not
37 the prefix so we can use whatever prefixes we want. For instance,
38 even if "urn:ietf:params:xml:ns:pidf:data-model" were declared with
39 the "pdm" prefix in the incoming document and with "dm" here,
40 "dm:device" would match "pdm:device" in the document.
41 -->
42
43 <xsl:output method="xml" indent="yes"/>
44 <xsl:strip-space elements="*"/>
45
46 <!--
47 Even though the "presence", "tuple", and "status" elements won't have namespaces in the
48 incoming PIDF document, we have to use the pseudo-namespace "def" here because of namespace
49 processing quirks in libxml2 and libxslt. We don't use namespace prefixes in the output
50 document at all.
51 -->
52 <xsl:template match="/def:presence">
53 <xsl:element name="presence">
54 <xsl:attribute name="entity"><xsl:value-of select="@entity"/></xsl:attribute>
55 <!--
56 We only want devices, tuples and persons (in that order) that
57 have location-info elements.
58 -->
59 <xsl:apply-templates select="dm:device[./gp:geopriv/gp:location-info]"/>
60 <xsl:apply-templates select="def:tuple[./def:status/gp:geopriv/gp:location-info]"/>
61 <xsl:apply-templates select="dm:person[.//gp:geopriv/gp:location-info]"/>
62 </xsl:element>
63 </xsl:template>
64
65 <xsl:template name="geopriv">
66 <xsl:apply-templates select=".//gp:geopriv/gp:location-info"/>
67 <xsl:apply-templates select=".//gp:geopriv/gp:usage-rules"/>
68 <xsl:apply-templates select=".//gp:geopriv/gp:method"/>
69 <xsl:apply-templates select=".//gp:geopriv/gp:note-well"/>
70 </xsl:template>
71
72 <xsl:template match="def:tuple">
73 <xsl:element name="tuple">
74 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
75 <xsl:call-template name="geopriv"/>
76 <xsl:apply-templates select="./def:timestamp"/>
77 <xsl:if test="./dm:deviceID">
78 <deviceID>
79 <xsl:value-of select="./dm:deviceID"/>
80 </deviceID>
81 </xsl:if>
82 </xsl:element>
83 </xsl:template>
84
85 <xsl:template match="dm:device|dm:person">
86 <xsl:element name="{local-name(.)}">
87 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
88 <xsl:call-template name="geopriv"/>
89 <xsl:apply-templates select="./dm:timestamp"/>
90 <xsl:if test="./dm:deviceID">
91 <deviceID>
92 <xsl:value-of select="./dm:deviceID"/>
93 </deviceID>
94 </xsl:if>
95 </xsl:element>
96 </xsl:template>
97
98 <xsl:template match="gp:geopriv/gp:location-info">
99 <xsl:element name="location-info">
100 <xsl:choose>
101 <xsl:when test="ca:civicAddress">
102 <xsl:attribute name="format">civicAddress</xsl:attribute>
103 </xsl:when>
104 <xsl:when test="gml:*">
105 <xsl:attribute name="format">gml</xsl:attribute>
106 </xsl:when>
107 <xsl:when test="gs:*">
108 <xsl:attribute name="format">gml</xsl:attribute>
109 </xsl:when>
110 </xsl:choose>
111 <xsl:apply-templates/> <!-- Down we go! -->
112 </xsl:element>
113 </xsl:template>
114
115 <!-- Civic Address -->
116 <xsl:template match="gp:location-info/ca:civicAddress">
117 <xsl:element name="civicAddress">
118 <xsl:attribute name="lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
119 <!-- The for-each seems to be slightly faster than applying another template -->
120 <xsl:for-each select="./*">
121 <xsl:call-template name="name-value" />
122 </xsl:for-each>
123 </xsl:element>
124 </xsl:template>
125
126 <!-- End of Civic Address. Back up to location-info. -->
127
128 <!-- The GML shapes: gml:Point, gs:Circle, etc. -->
129 <xsl:template match="gp:location-info/gml:*|gp:location-info/gs:*">
130 <xsl:element name="{local-name(.)}">
131 <xsl:choose>
132 <xsl:when test="@srsName = 'urn:ogc:def:crs:EPSG::4326'">
133 <xsl:attribute name="srsName">2d</xsl:attribute>
134 </xsl:when>
135 <xsl:when test="@srsName = 'urn:ogc:def:crs:EPSG::4979'">
136 <xsl:attribute name="srsName">3d</xsl:attribute>
137 </xsl:when>
138 <xsl:otherwise>
139 <xsl:attribute name="srsName">unknown</xsl:attribute>
140 </xsl:otherwise>
141 </xsl:choose>
142 <xsl:apply-templates /> <!-- Down we go! -->
143 </xsl:element>
144 </xsl:template>
145
146 <!-- The supported GML attributes -->
147 <xsl:template match="gs:orientation"><xsl:call-template name="angle" /></xsl:template>
148 <xsl:template match="gs:radius"><xsl:call-template name="length" /></xsl:template>
149 <xsl:template match="gs:height"><xsl:call-template name="length" /></xsl:template>
150 <xsl:template match="gs:semiMajorAxis"><xsl:call-template name="length" /></xsl:template>
151 <xsl:template match="gs:semiMinorAxis"><xsl:call-template name="length" /></xsl:template>
152 <xsl:template match="gs:verticalAxis"><xsl:call-template name="length" /></xsl:template>
153 <xsl:template match="gs:innerRadius"><xsl:call-template name="length" /></xsl:template>
154 <xsl:template match="gs:outerRadius"><xsl:call-template name="length" /></xsl:template>
155 <xsl:template match="gs:startAngle"><xsl:call-template name="angle" /></xsl:template>
156 <xsl:template match="gs:openingAngle"><xsl:call-template name="angle" /></xsl:template>
157 <xsl:template match="gml:pos"><xsl:call-template name="name-value" /></xsl:template>
158 <xsl:template match="gml:posList"><xsl:call-template name="name-value" /></xsl:template>
159
160 <!-- The GML attribute types -->
161 <xsl:template name="name-value">
162 <xsl:element name="{local-name(.)}">
163 <xsl:value-of select="normalize-space(.)"/>
164 </xsl:element>
165 </xsl:template>
166
167 <xsl:template name="length"><xsl:call-template name="name-value" /></xsl:template>
168
169 <xsl:template name="angle">
170 <xsl:element name="{local-name(.)}">
171 <xsl:choose>
172 <xsl:when test="@uom = 'urn:ogc:def:uom:EPSG::9101'">
173 <xsl:attribute name="uom">radians</xsl:attribute></xsl:when>
174 <xsl:otherwise>
175 <xsl:attribute name="uom">degrees</xsl:attribute></xsl:otherwise>
176 </xsl:choose>
177 <xsl:value-of select="normalize-space(.)"/>
178 </xsl:element>
179 </xsl:template>
180
181 <!-- End of GML. Back up to location-info -->
182
183 <xsl:template match="gp:location-info/con:confidence">
184 <xsl:element name="{local-name(.)}">
185 <xsl:attribute name="pdf"><xsl:value-of select="@pdf"/></xsl:attribute>
186 <xsl:value-of select="normalize-space(.)" />
187 </xsl:element>
188 </xsl:template>
189
190 <!-- End of location-info. Back up to geopriv -->
191
192 <xsl:template match="gp:geopriv/gp:usage-rules">
193 <xsl:element name="usage-rules">
194 <xsl:for-each select="./*">
195 <xsl:call-template name="name-value" />
196 </xsl:for-each>
197 </xsl:element>
198 </xsl:template>
199
200 <xsl:template match="gp:geopriv/gp:method">
201 <xsl:call-template name="name-value" />
202 </xsl:template>
203
204 <xsl:template match="gp:geopriv/gp:note-well">
205 <xsl:element name="note-well">
206 <xsl:value-of select="." />
207 </xsl:element>
208 </xsl:template>
209
210 <!-- End of geopriv. Back up to device/tuple/person -->
211
212 <xsl:template match="def:timestamp|dm:timestamp">
213 <xsl:call-template name="name-value" />
214 </xsl:template>
215
216
217 </xsl:stylesheet>