1 |
4551
|
walbridge
|
<?xml version="1.0"?>
|
2 |
|
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:eml="eml://ecoinformatics.org/eml-2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
|
3 |
|
|
<xsl:output method="xml" indent="yes"/>
|
4 |
|
|
<xsl:strip-space elements="*"/>
|
5 |
|
|
|
6 |
|
|
<xsl:template match="/* ">
|
7 |
|
|
<!--handle top level element-->
|
8 |
|
|
<xsl:element name="eml:eml">
|
9 |
|
|
<xsl:copy-of select="@*"/>
|
10 |
|
|
<xsl:attribute name="xsi:schemaLocation">eml://ecoinformatics.org/eml-2.1.0 eml.xsd</xsl:attribute>
|
11 |
|
|
|
12 |
|
|
<!-- move the access sub tree to top level-->
|
13 |
|
|
<xsl:apply-templates mode="copy-top-access-tree" select="/*/dataset/access"/>
|
14 |
|
|
<xsl:apply-templates mode="copy-top-access-tree" select="/*/citation/access"/>
|
15 |
|
|
<xsl:apply-templates mode="copy-top-access-tree" select="/*/software/access"/>
|
16 |
|
|
<xsl:apply-templates mode="copy-top-access-tree" select="/*/protocol/access"/>
|
17 |
|
|
|
18 |
|
|
<xsl:for-each select="/*/*">
|
19 |
|
|
<xsl:choose>
|
20 |
|
|
<xsl:when test="name()='dataset'">
|
21 |
|
|
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
|
22 |
|
|
<xsl:copy-of select="@*"/>
|
23 |
|
|
<xsl:apply-templates mode="handle-elements-under-main-module" select="."/>
|
24 |
|
|
</xsl:element>
|
25 |
|
|
</xsl:when>
|
26 |
|
|
|
27 |
|
|
<xsl:when test="name()='citation'">
|
28 |
|
|
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
|
29 |
|
|
<xsl:copy-of select="@*"/>
|
30 |
|
|
<xsl:apply-templates mode="handle-elements-under-main-module" select="."/>
|
31 |
|
|
</xsl:element>
|
32 |
|
|
</xsl:when>
|
33 |
|
|
|
34 |
|
|
<xsl:when test="name()='software'">
|
35 |
|
|
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
|
36 |
|
|
<xsl:copy-of select="@*"/>
|
37 |
|
|
<xsl:apply-templates mode="handle-elements-under-main-module" select="."/>
|
38 |
|
|
</xsl:element>
|
39 |
|
|
</xsl:when>
|
40 |
|
|
|
41 |
|
|
<xsl:when test="name()='protocol'">
|
42 |
|
|
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
|
43 |
|
|
<xsl:copy-of select="@*"/>
|
44 |
|
|
<xsl:apply-templates mode="handle-elements-under-main-module" select="."/>
|
45 |
|
|
</xsl:element>
|
46 |
|
|
</xsl:when>
|
47 |
|
|
|
48 |
|
|
<xsl:when test="name()='additionalMetadata'">
|
49 |
|
|
<xsl:apply-templates mode="handle-additionalMetadata" select="."/>
|
50 |
|
|
</xsl:when>
|
51 |
|
|
|
52 |
|
|
</xsl:choose>
|
53 |
|
|
</xsl:for-each>
|
54 |
|
|
</xsl:element>
|
55 |
|
|
</xsl:template>
|
56 |
|
|
|
57 |
|
|
<!-- handle make changes under main module (dataset, citation, protocol and software) -->
|
58 |
|
|
<xsl:template mode="handle-elements-under-main-module" match="*">
|
59 |
|
|
<xsl:for-each select="./*">
|
60 |
|
|
<xsl:choose>
|
61 |
|
|
<xsl:when test="name()='access'">
|
62 |
|
|
<xsl:apply-templates mode="do-nothing" select="."/>
|
63 |
|
|
</xsl:when>
|
64 |
|
|
<xsl:otherwise>
|
65 |
|
|
<xsl:apply-templates select="."/>
|
66 |
|
|
</xsl:otherwise>
|
67 |
|
|
</xsl:choose>
|
68 |
|
|
</xsl:for-each>
|
69 |
|
|
</xsl:template>
|
70 |
|
|
|
71 |
|
|
<!-- main template which will copy nodes recursively-->
|
72 |
|
|
<xsl:template match="*">
|
73 |
|
|
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
|
74 |
|
|
<xsl:copy-of select="@*"/>
|
75 |
|
|
<xsl:apply-templates/>
|
76 |
|
|
</xsl:element>
|
77 |
|
|
</xsl:template>
|
78 |
|
|
|
79 |
|
|
<!-- fixing attributeList/attribute/measurementScale/datetime -> .../dateTime -->
|
80 |
|
|
<xsl:template match="attributeList/attribute/measurementScale/datetime">
|
81 |
|
|
<xsl:element name="dateTime" namespace="{namespace-uri(.)}">
|
82 |
|
|
<xsl:copy-of select="@*"/>
|
83 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
84 |
|
|
</xsl:element>
|
85 |
|
|
</xsl:template>
|
86 |
|
|
|
87 |
|
|
<!-- change the name of element form method to methods -->
|
88 |
|
|
<xsl:template match="dataTable/method">
|
89 |
|
|
<xsl:element name="methods" namespace="{namespace-uri(.)}">
|
90 |
|
|
<xsl:copy-of select="@*"/>
|
91 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
92 |
|
|
</xsl:element>
|
93 |
|
|
</xsl:template>
|
94 |
|
|
|
95 |
|
|
<!-- change the name of element form method to methods -->
|
96 |
|
|
<xsl:template match="spatialRaster/method">
|
97 |
|
|
<xsl:element name="methods" namespace="{namespace-uri(.)}">
|
98 |
|
|
<xsl:copy-of select="@*"/>
|
99 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
100 |
|
|
</xsl:element>
|
101 |
|
|
</xsl:template>
|
102 |
|
|
|
103 |
|
|
<!-- change the name of element form method to methods -->
|
104 |
|
|
<xsl:template match="spatialVector/method">
|
105 |
|
|
<xsl:element name="methods" namespace="{namespace-uri(.)}">
|
106 |
|
|
<xsl:copy-of select="@*"/>
|
107 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
108 |
|
|
</xsl:element>
|
109 |
|
|
</xsl:template>
|
110 |
|
|
|
111 |
|
|
<!-- change the name of element form method to methods -->
|
112 |
|
|
<xsl:template match="view/method">
|
113 |
|
|
<xsl:element name="methods" namespace="{namespace-uri(.)}">
|
114 |
|
|
<xsl:copy-of select="@*"/>
|
115 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
116 |
|
|
</xsl:element>
|
117 |
|
|
</xsl:template>
|
118 |
|
|
|
119 |
|
|
<!-- change the name of element form method to methods -->
|
120 |
|
|
<xsl:template match="storedProcedure/method">
|
121 |
|
|
<xsl:element name="methods" namespace="{namespace-uri(.)}">
|
122 |
|
|
<xsl:copy-of select="@*"/>
|
123 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
124 |
|
|
</xsl:element>
|
125 |
|
|
</xsl:template>
|
126 |
|
|
|
127 |
|
|
<!-- change the name of element form method to methods -->
|
128 |
|
|
<xsl:template match="otherEntity/method">
|
129 |
|
|
<xsl:element name="methods" namespace="{namespace-uri(.)}">
|
130 |
|
|
<xsl:copy-of select="@*"/>
|
131 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
132 |
|
|
</xsl:element>
|
133 |
|
|
</xsl:template>
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
<!-- Move the access tree of data file level from additionalMetadata part to physical/distribution or software/implementation/distribution part.
|
137 |
|
|
If we find the id of physical/distribution is in aditionalMetadata/describe and it
|
138 |
|
|
has sibling of access subtree, copy the subtree to physical/distribution -->
|
139 |
|
|
<xsl:template match="physical/distribution | software/implementation/distribution">
|
140 |
|
|
<xsl:element name="distribution" namespace="{namespace-uri(.)}">
|
141 |
|
|
<xsl:copy-of select="@*"/>
|
142 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
143 |
|
|
<!--distribution doesn't have any access node yet. Move the subtree from addtionalMetadata to distribution-->
|
144 |
|
|
<!--find the id in addtionalMetacat/describes-->
|
145 |
|
|
<xsl:variable name="id" select="@id"/>
|
146 |
|
|
<!-- count how many additionalMetadata/access describing same distribution is -->
|
147 |
|
|
<xsl:variable name="countAccessTree" select="count(/*/additionalMetadata[describes=$id]/access)"/>
|
148 |
|
|
<xsl:choose>
|
149 |
|
|
<xsl:when test="$countAccessTree=1">
|
150 |
|
|
<!-- only has one access tree, we need copy it to distribution-->
|
151 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="/*/additionalMetadata[describes=$id]/access"/>
|
152 |
|
|
</xsl:when>
|
153 |
|
|
<xsl:when test="$countAccessTree > 1">
|
154 |
|
|
<!-- has more than one access tree, we need merge them-->
|
155 |
|
|
<!--This means document have two or more addtionalMetadata
|
156 |
|
|
with access tree describing same distribution.
|
157 |
|
|
<additionalMetadata>
|
158 |
|
|
<describes>100</describe>
|
159 |
|
|
<access>...</access>
|
160 |
|
|
</additionalMetadata>
|
161 |
|
|
<additionalMetadata>
|
162 |
|
|
<describes>100</describe>
|
163 |
|
|
<access>...</access>
|
164 |
|
|
</additionalMetadata>-->
|
165 |
|
|
<xsl:variable name="totalOrderNumber" select="count(/*/additionalMetadata[describes=$id]/access)"/>
|
166 |
|
|
<xsl:variable name="totalAllowFirstNumber" select="count(/*/additionalMetadata[describes=$id]/access[@order='allowFirst'])"/>
|
167 |
|
|
<xsl:variable name="totalDenyFirstNumber" select="count(/*/additionalMetadata[describes=$id]/access[@order='denyFirst'])"/>
|
168 |
|
|
<xsl:choose>
|
169 |
|
|
<xsl:when test="$totalOrderNumber=$totalAllowFirstNumber or $totalOrderNumber=$totalDenyFirstNumber">
|
170 |
|
|
<!-- all access subtrees have same order, just merge it-->
|
171 |
|
|
<xsl:element name="access">
|
172 |
|
|
<xsl:copy-of select="/*/additionalMetadata[describes=$id]/access/@*"/>
|
173 |
|
|
<xsl:for-each select="/*/additionalMetadata[describes=$id]/access">
|
174 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
175 |
|
|
</xsl:for-each>
|
176 |
|
|
</xsl:element>
|
177 |
|
|
</xsl:when>
|
178 |
|
|
<xsl:otherwise>
|
179 |
|
|
<xsl:message terminate="yes">EML 2.0.1 document has more than one access subtrees in addtionalMetadata blocks describing same entity.
|
180 |
|
|
However, attributes "order" have different value. It is illegitimate. Please fix the EML 2.0.1 document first.
|
181 |
|
|
</xsl:message>
|
182 |
|
|
</xsl:otherwise>
|
183 |
|
|
</xsl:choose>
|
184 |
|
|
</xsl:when>
|
185 |
|
|
</xsl:choose>
|
186 |
|
|
</xsl:element>
|
187 |
|
|
</xsl:template>
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
<!-- copy access tree under dataset(or protocol, software and citation) to the top level -->
|
191 |
|
|
<xsl:template mode="copy-top-access-tree" match="*">
|
192 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="."/>
|
193 |
|
|
</xsl:template>
|
194 |
|
|
|
195 |
|
|
<!-- do nothing for this element (removing it)-->
|
196 |
|
|
<xsl:template mode="do-nothing" match="*">
|
197 |
|
|
</xsl:template>
|
198 |
|
|
|
199 |
|
|
<!-- copy node and children without namespace -->
|
200 |
|
|
<xsl:template mode="copy-no-ns" match="*">
|
201 |
|
|
<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
|
202 |
|
|
<xsl:copy-of select="@*"/>
|
203 |
|
|
<xsl:apply-templates mode="copy-no-ns"/>
|
204 |
|
|
</xsl:element>
|
205 |
|
|
</xsl:template>
|
206 |
|
|
|
207 |
|
|
<!--Handle additionMetadata part. Here are 4 scenarios:
|
208 |
|
|
1. <additionalMetadata>
|
209 |
|
|
<describes>100</describes>
|
210 |
|
|
<foo>.....</foo>
|
211 |
|
|
</additionalMetacata>
|
212 |
|
|
The result will be (foo deosn't euqal access):
|
213 |
|
|
<additionalMetadata>
|
214 |
|
|
<describes>100</describes>
|
215 |
|
|
<metadata><foo>.....</foo></metadata>
|
216 |
|
|
</additionalMetacata>
|
217 |
|
|
2. <additionalMetadata>
|
218 |
|
|
<describes>100</describes>
|
219 |
|
|
<describes>200</describes>
|
220 |
|
|
<access>.....</access>
|
221 |
|
|
</additionalMetacata>
|
222 |
|
|
Both 100 and 200 are referenced ids of pysical/distribtuion or software/implementation/distribution.
|
223 |
|
|
Since we moved the access part to distribution element, we don't need to keep the info.
|
224 |
|
|
So the output is blank - remvoing the additionalMetadata tree.
|
225 |
|
|
3. <additionalMetadata>
|
226 |
|
|
<describes>300</describes>
|
227 |
|
|
<describes>400</describes>
|
228 |
|
|
<access>.....</access>
|
229 |
|
|
</additionalMetacata>
|
230 |
|
|
300 is the referenced ids of pysical/distribtuion or software/implementation/distribution.
|
231 |
|
|
But 400 is not. So output will be:
|
232 |
|
|
<additionalMetadata>
|
233 |
|
|
<describes>400</describes>
|
234 |
|
|
<metadata><access>.....</access></metadata>
|
235 |
|
|
</additionalMetacata>
|
236 |
|
|
And we will give an warning message: 400 is a not distribution id and the eml201 document does not follow EML pratice.
|
237 |
|
|
4. <additionalMetadata>
|
238 |
|
|
<access>.....</access>
|
239 |
|
|
</additionalMetacata>
|
240 |
|
|
Since no describes, no access tree will move. So output will be:
|
241 |
|
|
<additionalMetadata>
|
242 |
|
|
<metadata><access>.....</access></metadata>
|
243 |
|
|
</additionalMetacata>
|
244 |
|
|
And we will give an warning message:No distribution id in addtionalMetadata/describes and the eml201 document does not follow EML pratice.
|
245 |
|
|
-->
|
246 |
|
|
<xsl:template mode="handle-additionalMetadata" match="*">
|
247 |
|
|
<!-- test if this additionalMetadata part has "access" element-->
|
248 |
|
|
<xsl:variable name="accessCount" select="count(access)" />
|
249 |
|
|
<xsl:choose>
|
250 |
|
|
<xsl:when test="$accessCount < 1">
|
251 |
|
|
<!-- no access tree here. Scenario 1 -->
|
252 |
|
|
<additionalMetadata>
|
253 |
|
|
<xsl:for-each select="./*">
|
254 |
|
|
<xsl:choose>
|
255 |
|
|
<xsl:when test="name()='describes'">
|
256 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="."/>
|
257 |
|
|
</xsl:when>
|
258 |
|
|
<xsl:otherwise>
|
259 |
|
|
<metadata>
|
260 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="."/>
|
261 |
|
|
</metadata>
|
262 |
|
|
</xsl:otherwise>
|
263 |
|
|
</xsl:choose>
|
264 |
|
|
</xsl:for-each>
|
265 |
|
|
</additionalMetadata>
|
266 |
|
|
</xsl:when>
|
267 |
|
|
<xsl:otherwise>
|
268 |
|
|
<!--additionalMetadata has access child-->
|
269 |
|
|
<xsl:variable name="describesCount" select="count(access)" />
|
270 |
|
|
<xsl:choose>
|
271 |
|
|
<xsl:when test="$describesCount=0">
|
272 |
|
|
<!-- scenario 4 -->
|
273 |
|
|
<additionalMetadata>
|
274 |
|
|
<metadata>
|
275 |
|
|
<xsl:apply-templates mode="copy-no-ns" select="./*"/>
|
276 |
|
|
</metadata>
|
277 |
|
|
</additionalMetadata>
|
278 |
|
|
<xsl:message terminate="no">additonalMetadata has access element, but doesn't have any describes element which references id of physical/distribution
|
279 |
|
|
or software/implementation/distribution elements. This document doesn't follow the EML practice.
|
280 |
|
|
</xsl:message>
|
281 |
|
|
</xsl:when>
|
282 |
|
|
<xsl:otherwise>
|
283 |
|
|
<xsl:for-each select="./describes">
|
284 |
|
|
<xsl:variable name="describesID" select="."/>
|
285 |
|
|
<xsl:variable name="distribution" select="count(//physical/distribution[@id=$describesID] | //software/implementation/distribution[@id=$describesID] )"/>
|
286 |
|
|
<xsl:if test="$distribution=0">
|
287 |
|
|
<xsl:message terminate="no">We removed the access tree from additionalMetadata. However, described ID doesn't reference any distribution id</xsl:message>
|
288 |
|
|
</xsl:if>
|
289 |
|
|
</xsl:for-each>
|
290 |
|
|
</xsl:otherwise>
|
291 |
|
|
</xsl:choose>
|
292 |
|
|
</xsl:otherwise>
|
293 |
|
|
</xsl:choose>
|
294 |
|
|
</xsl:template>
|
295 |
|
|
|
296 |
|
|
</xsl:stylesheet>
|