-
Notifications
You must be signed in to change notification settings - Fork 5
/
update-fixed-info.xsl
394 lines (342 loc) · 14.5 KB
/
update-fixed-info.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:gml="http://www.opengis.net/gml"
xmlns:srv="http://www.isotc211.org/2005/srv"
xmlns:gmx="http://www.isotc211.org/2005/gmx"
xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gvq="http://www.geoviqua.org/QualityInformationModel/4.0" exclude-result-prefixes="#all">
<xsl:include href="../iso19139/convert/functions.xsl"/>
<!-- ================================================================= -->
<xsl:template match="/root">
<xsl:apply-templates select="gvq:GVQ_Metadata"/>
</xsl:template>
<!-- ================================================================= -->
<xsl:template match="gvq:GVQ_Metadata">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<gmd:fileIdentifier>
<gco:CharacterString>
<xsl:value-of select="/root/env/uuid"/>
</gco:CharacterString>
</gmd:fileIdentifier>
<xsl:apply-templates select="gmd:language"/>
<xsl:apply-templates select="gmd:characterSet"/>
<xsl:choose>
<xsl:when test="/root/env/parentUuid!=''">
<gmd:parentIdentifier>
<gco:CharacterString>
<xsl:value-of select="/root/env/parentUuid"/>
</gco:CharacterString>
</gmd:parentIdentifier>
</xsl:when>
<xsl:when test="gmd:parentIdentifier">
<xsl:copy-of select="gmd:parentIdentifier"/>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()[not(self::gmd:language) and not(self::gmd:characterSet)]"/>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<!-- Do not process MD_Metadata header generated by previous template -->
<xsl:template match="gvq:GVQ_Metadata/gmd:fileIdentifier|gvq:GVQ_Metadata/gmd:parentIdentifier" priority="10"/>
<!-- ================================================================= -->
<xsl:template match="gmd:dateStamp">
<xsl:choose>
<xsl:when test="/root/env/changeDate">
<xsl:copy>
<gco:DateTime>
<xsl:value-of select="/root/env/changeDate"/>
</gco:DateTime>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- ================================================================= -->
<!-- Only set metadataStandardName and metadataStandardVersion
if not set. -->
<xsl:template match="gmd:metadataStandardName[@gco:nilReason='missing' or gco:CharacterString='']" priority="10">
<xsl:copy>
<gco:CharacterString>ISO 19115:2003/19139</gco:CharacterString>
</xsl:copy>
</xsl:template>
<xsl:template match="gmd:metadataStandardVersion[@gco:nilReason='missing' or gco:CharacterString='']" priority="10">
<xsl:copy>
<gco:CharacterString>1.0</gco:CharacterString>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<xsl:template match="@gml:id">
<xsl:choose>
<xsl:when test="normalize-space(.)=''">
<xsl:attribute name="gml:id">
<xsl:value-of select="generate-id(.)"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- ==================================================================== -->
<!-- Fix srsName attribute generate CRS:84 (EPSG:4326 with long/lat
ordering) by default -->
<xsl:template match="@srsName">
<xsl:choose>
<xsl:when test="normalize-space(.)=''">
<xsl:attribute name="srsName">
<xsl:text>CRS:84</xsl:text>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Add required gml attributes if missing -->
<xsl:template match="gml:Polygon[not(@gml:id) and not(@srsName)]">
<xsl:copy>
<xsl:attribute name="gml:id">
<xsl:value-of select="generate-id(.)"/>
</xsl:attribute>
<xsl:attribute name="srsName">
<xsl:text>urn:x-ogc:def:crs:EPSG:6.6:4326</xsl:text>
</xsl:attribute>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="*"/>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<xsl:template match="*[gco:CharacterString]">
<xsl:copy>
<xsl:apply-templates select="@*[not(name()='gco:nilReason')]"/>
<xsl:choose>
<xsl:when test="normalize-space(gco:CharacterString)=''">
<xsl:attribute name="gco:nilReason">
<xsl:choose>
<xsl:when test="@gco:nilReason"><xsl:value-of select="@gco:nilReason"/></xsl:when>
<xsl:otherwise>missing</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:when>
<xsl:when test="@gco:nilReason!='missing' and normalize-space(gco:CharacterString)!=''">
<xsl:copy-of select="@gco:nilReason"/>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<!-- codelists: set @codeList path -->
<!-- ================================================================= -->
<xsl:template match="gmd:LanguageCode[@codeListValue]" priority="10">
<gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/">
<xsl:apply-templates select="@*[name(.)!='codeList']"/>
</gmd:LanguageCode>
</xsl:template>
<xsl:template match="gmd:*[@codeListValue]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="codeList">
<xsl:value-of select="concat('http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#',local-name(.))"/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<!-- can't find the location of the 19119 codelists - so we make one up -->
<xsl:template match="srv:*[@codeListValue]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="codeList">
<xsl:value-of select="concat('http://www.isotc211.org/2005/iso19119/resources/Codelist/gmxCodelists.xml#',local-name(.))"/>
</xsl:attribute>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<!-- online resources: download -->
<!-- ================================================================= -->
<xsl:template match="gmd:CI_OnlineResource[matches(gmd:protocol/gco:CharacterString,'^WWW:DOWNLOAD-.*-http--download.*') and gmd:name]">
<xsl:variable name="fname" select="gmd:name/gco:CharacterString|gmd:name/gmx:MimeFileType"/>
<xsl:variable name="mimeType">
<xsl:call-template name="getMimeTypeFile">
<xsl:with-param name="datadir" select="/root/env/datadir"/>
<xsl:with-param name="fname" select="$fname"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy>
<xsl:copy-of select="@*"/>
<gmd:linkage>
<gmd:URL>
<xsl:choose>
<xsl:when test="/root/env/config/downloadservice/simple='true'">
<xsl:value-of select="concat(/root/env/siteURL,'/resources.get?uuid=',/root/env/uuid,'&fname=',$fname,'&access=private')"/>
</xsl:when>
<xsl:when test="/root/env/config/downloadservice/withdisclaimer='true'">
<xsl:value-of select="concat(/root/env/siteURL,'/file.disclaimer?uuid=',/root/env/uuid,'&fname=',$fname,'&access=private')"/>
</xsl:when>
<xsl:otherwise> <!-- /root/env/config/downloadservice/leave='true' -->
<xsl:value-of select="gmd:linkage/gmd:URL"/>
</xsl:otherwise>
</xsl:choose>
</gmd:URL>
</gmd:linkage>
<xsl:copy-of select="gmd:protocol"/>
<xsl:copy-of select="gmd:applicationProfile"/>
<gmd:name>
<gmx:MimeFileType type="{$mimeType}">
<xsl:value-of select="$fname"/>
</gmx:MimeFileType>
</gmd:name>
<xsl:copy-of select="gmd:description"/>
<xsl:copy-of select="gmd:function"/>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<!-- online resources: link-to-downloadable data etc -->
<!-- ================================================================= -->
<xsl:template match="gmd:CI_OnlineResource[starts-with(gmd:protocol/gco:CharacterString,'WWW:LINK-') and contains(gmd:protocol/gco:CharacterString,'http--download')]">
<xsl:variable name="mimeType">
<xsl:call-template name="getMimeTypeUrl">
<xsl:with-param name="linkage" select="gmd:linkage/gmd:URL"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="gmd:linkage"/>
<xsl:copy-of select="gmd:protocol"/>
<xsl:copy-of select="gmd:applicationProfile"/>
<gmd:name>
<gmx:MimeFileType type="{$mimeType}"/>
</gmd:name>
<xsl:copy-of select="gmd:description"/>
<xsl:copy-of select="gmd:function"/>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<xsl:template match="gmx:FileName[name(..)!='gmd:contactInstructions']">
<xsl:copy>
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="/root/env/config/downloadservice/simple='true'">
<xsl:value-of select="concat(/root/env/siteURL,'/resources.get?uuid=',/root/env/uuid,'&fname=',.,'&access=private')"/>
</xsl:when>
<xsl:when test="/root/env/config/downloadservice/withdisclaimer='true'">
<xsl:value-of select="concat(/root/env/siteURL,'/file.disclaimer?uuid=',/root/env/uuid,'&fname=',.,'&access=private')"/>
</xsl:when>
<xsl:otherwise> <!-- /root/env/config/downloadservice/leave='true' -->
<xsl:value-of select="@src"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<!-- Do not allow to expand operatesOn sub-elements
and constrain users to use uuidref attribute to link
service metadata to datasets. This will avoid to have
error on XSD validation. -->
<xsl:template match="srv:operatesOn|gmd:featureCatalogueCitation">
<xsl:copy>
<xsl:copy-of select="@uuidref"/>
<xsl:if test="@uuidref">
<xsl:choose>
<xsl:when test="not(string(@xlink:href)) or starts-with(@xlink:href, /root/env/siteURL)">
<xsl:attribute name="xlink:href">
<xsl:value-of select="concat(/root/env/siteURL,'/csw?service=CSW&request=GetRecordById&version=2.0.2&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full&id=',@uuidref)"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="@xlink:href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:copy>
</xsl:template>
<!-- ================================================================= -->
<!-- Set local identifier to the first 3 letters of iso code. Locale ids
are used for multilingual charcterString using #iso2code for referencing.
-->
<xsl:template match="gmd:PT_Locale">
<xsl:element name="gmd:{local-name()}">
<xsl:variable name="id" select="upper-case(
substring(gmd:languageCode/gmd:LanguageCode/@codeListValue, 1, 3))"/>
<xsl:apply-templates select="@*"/>
<xsl:if test="@id and (normalize-space(@id)='' or normalize-space(@id)!=$id)">
<xsl:attribute name="id">
<xsl:value-of select="$id"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
<!-- Apply same changes as above to the gmd:LocalisedCharacterString -->
<xsl:variable name="language" select="//gmd:PT_Locale" /> <!-- Need list of all locale -->
<xsl:template match="gmd:LocalisedCharacterString">
<xsl:element name="gmd:{local-name()}">
<xsl:variable name="currentLocale" select="upper-case(replace(normalize-space(@locale), '^#', ''))"/>
<xsl:variable name="ptLocale" select="$language[upper-case(replace(normalize-space(@id), '^#', ''))=string($currentLocale)]"/>
<xsl:variable name="id" select="upper-case(substring($ptLocale/gmd:languageCode/gmd:LanguageCode/@codeListValue, 1, 3))"/>
<xsl:apply-templates select="@*"/>
<xsl:if test="$id != '' and ($currentLocale='' or @locale!=concat('#', $id)) ">
<xsl:attribute name="locale">
<xsl:value-of select="concat('#',$id)"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
<!-- ================================================================= -->
<!-- Adjust the namespace declaration - In some cases name() is used to get the
element. The assumption is that the name is in the format of <ns:element>
however in some cases it is in the format of <element xmlns=""> so the
following will convert them back to the expected value. This also corrects the issue
where the <element xmlns=""> loose the xmlns="" due to the exclude-result-prefixes="#all" -->
<!-- Note: Only included prefix gml, gmd and gco for now. -->
<!-- TODO: Figure out how to get the namespace prefix via a function so that we don't need to hard code them -->
<!-- ================================================================= -->
<xsl:template name="correct_ns_prefix">
<xsl:param name="element" />
<xsl:param name="prefix" />
<xsl:choose>
<xsl:when test="local-name($element)=name($element) and $prefix != '' ">
<xsl:element name="{$prefix}:{local-name($element)}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="gmd:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:with-param name="element" select="."/>
<xsl:with-param name="prefix" select="'gmd'"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="gco:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:with-param name="element" select="."/>
<xsl:with-param name="prefix" select="'gco'"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="gml:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:with-param name="element" select="."/>
<xsl:with-param name="prefix" select="'gml'"/>
</xsl:call-template>
</xsl:template>
<!-- ================================================================= -->
<!-- copy everything else as is -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>