transform.xslt 17.7 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
                version="2.0"
                xmlns:ns2="http://purl.org/dc/elements/1.1/"
                xmlns:foxml="info:fedora/fedora-system:def/foxml#"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:audit="info:fedora/fedora-system:def/audit#"
                xmlns:dc="http://purl.org/dc/elements/1.1/"
                xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
                xmlns:fedora="info:fedora/fedora-system:def/relations-external#"
                xmlns:fedora-model="info:fedora/fedora-system:def/model#"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
16
                xmlns:core="urn:ebu:metadata-schema:ebuCore_2012"
Jonas Waeber's avatar
Jonas Waeber committed
17
18
19
20
21
22
23
24
25
26
27
                xpath-default-namespace="urn:ebu:metadata-schema:ebuCore_2012">

    <xsl:output
            indent="yes"
            method="xml"
    />

    <!--<xsl:template match="/digitalObject/datastream/datastreamVersion/xmlContent/ebuCoreMain/coreMetadata">
        <xsl:copy-of select="."/>
    </xsl:template>-->

28
29
30
31
    <xsl:template match="@*|node()">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>

Jonas Waeber's avatar
Jonas Waeber committed
32

33
    <xsl:template match="core:coreMetadata">
Jonas Waeber's avatar
Jonas Waeber committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        <xsl:element name="record">
            <!--<xsl:apply-templates select="test"/>
            <xsl:apply-templates select="title, ns2:title, alternativeTitle, subject, description, format/essenceLocator, format/medium, type/*, references"/>-->
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>

    <!-- content of child node is copied to parent node -->
    <xsl:template match="title | format/essenceLocator | format/duration | format/start | language | references | coverage/spatial/location">
        <xsl:element name="{local-name()}">
            <xsl:value-of select="child::*"/>
        </xsl:element>
    </xsl:template>

    <!-- content of typeLabel is transformed to an element name and content of child node is copied to it-->
Jonas Waeber's avatar
Jonas Waeber committed
49
    <xsl:template match="description[@typeLabel] | alternativeTitle[@typeLabel] | subject[@typeLabel] | relation[@typeLabel]">
Jonas Waeber's avatar
Jonas Waeber committed
50
        <xsl:variable name="typeLabel" select="@typeLabel"/>
Silvia Witzig's avatar
Silvia Witzig committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        <xsl:choose>
            <xsl:when test="$typeLabel = 'FeaturedIndividual'">
                <xsl:analyze-string select ="replace(child::*, ' ; ', 'x;x')" regex = ";\s">
                    <xsl:matching-substring/>
                    <xsl:non-matching-substring>
                        <xsl:element name="FeaturedIndividual">
                            <xsl:choose>
                                <xsl:when test="matches(., ',')">
                                    <xsl:value-of select="replace(concat(substring-after(., ', '), ' ', substring-before(., ', ')), 'x;x', ' ; ')"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="replace(., 'x;x', ' ; ')"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:element>
                    </xsl:non-matching-substring>
                </xsl:analyze-string>
            </xsl:when>
            <xsl:otherwise>
                <xsl:element name="{$typeLabel}">
                    <xsl:value-of select="child::*"/>
                </xsl:element>
            </xsl:otherwise>
        </xsl:choose>
Jonas Waeber's avatar
Jonas Waeber committed
75
76
77
    </xsl:template>

    <!-- content of typeLabel is copied as content of the node -->
Jonas Waeber's avatar
Jonas Waeber committed
78
    <xsl:template match="format/medium | format/dataFormat/captioningFormat | type/genre">
Jonas Waeber's avatar
Jonas Waeber committed
79
80
81
82
83
        <xsl:element name="{local-name()}">
            <xsl:value-of select="@typeLabel | @language"/>
        </xsl:element>
    </xsl:template>

Jonas Waeber's avatar
Jonas Waeber committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    <xsl:template match="type/objectType">
        <xsl:element name="objectType">
            <xsl:choose>
                <xsl:when test="matches(@typeLabel,'film','i')">
                    <xsl:text>Film</xsl:text>
                </xsl:when>
                <xsl:when test="matches(@typeLabel,'photograph|foto','i')">
                    <xsl:text>Foto</xsl:text>
                </xsl:when>
                <xsl:when test="matches(@typeLabel,'radio','i')">
                    <xsl:text>Radio</xsl:text>
                </xsl:when>
                <xsl:when test="matches(@typeLabel,'television|tv','i')">
                    <xsl:text>TV</xsl:text>
                </xsl:when>
                <xsl:when test="matches(@typeLabel,'ton|sound','i')">
                    <xsl:text>Ton</xsl:text>
                </xsl:when>
                <xsl:when test="matches(@typeLabel,'video','i')">
                    <xsl:text>Video</xsl:text>
                </xsl:when>
105
106
107
                <xsl:when test="matches(@typeLabel,'tbs','i')">
                    <xsl:text>Tonbildschau</xsl:text>
                </xsl:when>
Jonas Waeber's avatar
Jonas Waeber committed
108
109
110
111
            </xsl:choose>
        </xsl:element>
    </xsl:template>

Jonas Waeber's avatar
Jonas Waeber committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    <xsl:template match="identifier">
        <xsl:variable name="typeLabel" select="@typeLabel"/>
        <xsl:element name="identifier{$typeLabel}">
            <xsl:value-of select="child::ns2:identifier"/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="format/videoFormat | format/imageFormat | format/audioFormat">
        <xsl:variable name="format" select="local-name()"/>
        <xsl:for-each select="technicalAttributeString">
            <xsl:variable name="typeLabel" select="@typeLabel"/>
            <xsl:element name="{$format}{$typeLabel}">
                <xsl:value-of select="."/>
            </xsl:element>
        </xsl:for-each>
Jonas Waeber's avatar
Jonas Waeber committed
127
128
129
130
131
132
133
134
135
136
137
138
        <xsl:for-each select="width | height">
            <xsl:variable name="local" select="local-name()"/>
            <xsl:variable name="unit" select="@unit"/>
            <xsl:element name="{$local}">
                <xsl:value-of select="concat(., ' ', $unit)"/>
            </xsl:element>
        </xsl:for-each>
        <xsl:for-each select="audioTrackConfiguration">
            <xsl:element name="audioTrackConfiguration">
                <xsl:value-of select="@typeLabel"/>
            </xsl:element>
        </xsl:for-each>
Jonas Waeber's avatar
Jonas Waeber committed
139
140
141
142
143
    </xsl:template>

    <xsl:template match="contributor | creator | publisher">
        <xsl:variable name="type" select="local-name()"/>
        <xsl:for-each select=".">
Jonas Waeber's avatar
Jonas Waeber committed
144
            <xsl:variable name="role" select="child::role/@typeLabel[. != '']"/>
Jonas Waeber's avatar
Jonas Waeber committed
145
            <xsl:choose>
Jonas Waeber's avatar
Jonas Waeber committed
146
                <xsl:when test="$role = 'ResponsibleInstitution'"/>
Silvia Witzig's avatar
Silvia Witzig committed
147
                <xsl:when test="$role = 'Producer' or $role = 'Production' or $role = 'Produktion'">
Jonas Waeber's avatar
Jonas Waeber committed
148
149
150
151
152
153
154
155
156
157
158
159
160
                    <xsl:choose>
                        <xsl:when test="child::organisationDetails">
                            <xsl:element name="producerCorporateBodyName">
                                <xsl:value-of select="descendant::organisationName"/>
                            </xsl:element>
                        </xsl:when>
                        <xsl:when test="child::contactDetails">
                            <xsl:element name="producerPersonName">
                                <xsl:value-of select="descendant::name"/>
                            </xsl:element>
                        </xsl:when>
                    </xsl:choose>
                </xsl:when>
Silvia Witzig's avatar
Silvia Witzig committed
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
                <!-- To be used for all SRF RecordSets where a Redaktion is recorded as Person in the data -->
                <!--<xsl:when test="$role = 'Redaktion'">
                    <xsl:element name="{$type}CorporateBody">
                        <xsl:element name="name">
                            <xsl:value-of select="descendant::name"/>
                        </xsl:element>
                        <xsl:if test="$role">
                            <xsl:element name="role">
                                <xsl:value-of select="$role"/>
                            </xsl:element>
                        </xsl:if>
                    </xsl:element>
                </xsl:when>-->
                <!-- To be used for all Tanzarchiv RecordSets where a Kompanie is recorded as Person in the data -->
                <!--<xsl:when test="$role = 'Kompanie / Compagnie'">
                    <xsl:element name="{$type}CorporateBody">
                        <xsl:element name="name">
                            <xsl:value-of select="descendant::name"/>
                        </xsl:element>
                        <xsl:if test="$role">
                            <xsl:element name="role">
                                <xsl:value-of select="$role"/>
                            </xsl:element>
                        </xsl:if>
                    </xsl:element>
                </xsl:when>-->
Jonas Waeber's avatar
Jonas Waeber committed
187
188
189
190
191
                <xsl:when test="child::organisationDetails">
                    <xsl:element name="{$type}CorporateBody">
                        <xsl:element name="name">
                            <xsl:value-of select="descendant::organisationName"/>
                        </xsl:element>
Jonas Waeber's avatar
Jonas Waeber committed
192
                        <xsl:if test="$role">
Jonas Waeber's avatar
Jonas Waeber committed
193
                            <xsl:element name="role">
Jonas Waeber's avatar
Jonas Waeber committed
194
                                <xsl:value-of select="$role"/>
Jonas Waeber's avatar
Jonas Waeber committed
195
196
197
198
199
                            </xsl:element>
                        </xsl:if>
                    </xsl:element>
                </xsl:when>
                <xsl:when test="child::contactDetails">
Silvia Witzig's avatar
Silvia Witzig committed
200
201
202
203
204
205
206
207
208
209
210
                    <xsl:choose>
                        <xsl:when test="matches(descendant::name,'^\(inconnu\)$')">
                            <xsl:element name="{$type}Agent">
                                <xsl:element name="name">
                                    <xsl:value-of select="descendant::name"/>
                                </xsl:element>
                                <xsl:if test="$role">
                                    <xsl:element name="role">
                                        <xsl:value-of select="$role"/>
                                    </xsl:element>
                                </xsl:if>
Jonas Waeber's avatar
Jonas Waeber committed
211
                            </xsl:element>
Silvia Witzig's avatar
Silvia Witzig committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:element name="{$type}Person">
                                <xsl:element name="name">
                                    <xsl:value-of select="replace(descendant::name, ' et |, |/ ', ';' )"/>
                                </xsl:element>
                                <xsl:if test="$role">
                                    <xsl:element name="role">
                                        <xsl:value-of select="$role"/>
                                    </xsl:element>
                                </xsl:if>
                            </xsl:element>
                        </xsl:otherwise>
                    </xsl:choose>
Jonas Waeber's avatar
Jonas Waeber committed
226
227
228
229
230
231
                </xsl:when>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="rights[@typeLabel='Access']/ns2:rights">
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
        <xsl:if test="matches(.,'onsite')">
            <xsl:element name="accessPhysical">
                <xsl:text>onsite</xsl:text>
            </xsl:element>
        </xsl:if>
        <xsl:if test="matches(.,'noonsite')">
            <xsl:element name="accessPhysical">
                <xsl:text>noonsite</xsl:text>
            </xsl:element>
        </xsl:if>
        <xsl:if test="matches(.,'public')">
            <xsl:element name="accessDigital">
                <xsl:text>public</xsl:text>
            </xsl:element>
            <xsl:element name="rightsStatementText">
                <xsl:text>Copyright Not Evaluated (CNE)</xsl:text>
            </xsl:element>
            <xsl:element name="rightsStatementURL">
                <xsl:text>http://rightsstatements.org/vocab/CNE/1.0/</xsl:text>
            </xsl:element>
        </xsl:if>
        <xsl:if test="matches(.,'private')">
            <xsl:element name="accessDigital">
                <xsl:text>private</xsl:text>
            </xsl:element>
            <xsl:element name="rightsStatementText">
                <xsl:text>Copyright Not Evaluated (CNE)</xsl:text>
            </xsl:element>
            <xsl:element name="rightsStatementURL">
                <xsl:text>http://rightsstatements.org/vocab/CNE/1.0/</xsl:text>
            </xsl:element>
        </xsl:if>
        <xsl:if test="matches(.,'faro')">
            <xsl:element name="accessDigital">
                <xsl:text>faro</xsl:text>
            </xsl:element>
            <xsl:element name="rightsStatementText">
                <xsl:text>Copyright Not Evaluated (CNE)</xsl:text>
            </xsl:element>
            <xsl:element name="rightsStatementURL">
                <xsl:text>http://rightsstatements.org/vocab/CNE/1.0/</xsl:text>
            </xsl:element>
        </xsl:if>
Jonas Waeber's avatar
Jonas Waeber committed
275
276
    </xsl:template>

Silvia Witzig's avatar
Silvia Witzig committed
277
    <xsl:template match="rights[@typeLabel='Holder']/rightsHolder/contactDetails/name | rights[@typeLabel='Holder']/ns2:rights">
Jonas Waeber's avatar
Jonas Waeber committed
278
279
280
281
282
        <xsl:element name="rightsHolder">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>

Silvia Witzig's avatar
Silvia Witzig committed
283
284
285
286
287
288
    <xsl:template match="rights[@typeLabel='Usage']/ns2:rights">
        <xsl:element name="rightsUsage">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>

289
    <xsl:template match="core:coreMetadata/ns2:source">
Jonas Waeber's avatar
Jonas Waeber committed
290
291
292
293
294
        <xsl:element name="source">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>

295
296
    <xsl:template match="date/created | date/issued | temporal/PeriodOfTime">
        <xsl:variable name="date" select="local-name()"/>
Jonas Waeber's avatar
Jonas Waeber committed
297
        <xsl:for-each select=".">
298
299
300
301
302
303
            <xsl:element name="{$date}Date">
                <xsl:choose>
                    <xsl:when test="descendant::periodName">
                        <xsl:value-of select="descendant::periodName"/>
                    </xsl:when>
                    <xsl:otherwise>
Jonas Waeber's avatar
Jonas Waeber committed
304
                        <xsl:call-template name="dates"/>
305
306
307
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:element>
Jonas Waeber's avatar
Jonas Waeber committed
308
309
310
311
        </xsl:for-each>
    </xsl:template>

    <xsl:template name="dates">
Jonas Waeber's avatar
Jonas Waeber committed
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
            <xsl:variable name="startDate" select="@startDate[. != '']"/>
            <xsl:variable name="startYear" select="@startYear[. != '']"/>
            <xsl:variable name="startTime" select="@startTime[. != '']"/>
            <xsl:variable name="endDate" select="@endDate[. != '']"/>
            <xsl:variable name="endYear" select="@endYear[. != '']"/>
            <xsl:variable name="period" select="@period[. != '']"/>

            <xsl:choose>
                <!-- Combinations which are not present in created/issued/temporal and are not processed:
                     * endYear and startDate
                     * period and endDate and startYear
                     * period and endYear and startDate
                     * startTime in another combination but with startDate
                     * period and endDate only
                -->
                <xsl:when test="$startDate and not($endDate | $endYear | $period | $startTime)">
                    <xsl:value-of select="$startDate"/>
                </xsl:when>
                <xsl:when test="$startYear and not($endDate | $endYear | $period | $startTime)">
                    <xsl:value-of select="$startYear"/>
                </xsl:when>
                <xsl:when test="$startDate and $endDate and not($period | $startTime)">
                    <xsl:value-of select="concat($startDate, '/', $endDate)"/>
                </xsl:when>
                <xsl:when test="$startYear and $endDate and not($period | $startTime)">
                    <xsl:value-of select="concat($startYear, '/', $endDate)"/>
                </xsl:when>
                <xsl:when test="$startYear and $endYear and not($period | $startTime)">
                    <xsl:value-of select="concat($startYear, '/', $endYear)"/>
                </xsl:when>
                <xsl:when test="$startTime">
                    <xsl:value-of select="concat($startDate, 'T', $startTime)"/>
                </xsl:when>
                <xsl:when test="$endDate and not ($startDate | $startYear | $period)">
                    <xsl:value-of select="concat('?/', $endDate)"/>
                </xsl:when>
                <xsl:when test="$endYear and not ($startDate | $startYear | $period)">
                    <xsl:value-of select="concat('?/', $endYear)"/>
                </xsl:when>
                <xsl:when test="$period and not($endDate | $endYear | $startDate | $startYear)">
                    <xsl:value-of select="$period"/>
                </xsl:when>
                <xsl:when test="$period and $startDate and not ($endDate | $endYear)">
                    <xsl:value-of select="concat($period, ' ', $startDate)"/>
                </xsl:when>
                <xsl:when test="$period and $startYear and not ($endDate | $endYear)">
                    <xsl:value-of select="concat($period, ' ', $startYear)"/>
                </xsl:when>
                <xsl:when test="$period and $startDate and $endDate">
                    <xsl:value-of select="concat($period, ' ', $startDate, '/', $endDate)"/>
                </xsl:when>
                <xsl:when test="$period and $startYear and $endYear">
                    <xsl:choose>
                        <xsl:when test="matches(@period,concat(@startYear, '-', @endYear))">
                            <xsl:value-of select="concat($startYear, '/', $endYear)"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat($period, ' ', $startYear, '/', $endYear)"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
            </xsl:choose>
Jonas Waeber's avatar
Jonas Waeber committed
374
375
376
    </xsl:template>

    <!-- field to delete -->
Silvia Witzig's avatar
Silvia Witzig committed
377
    <xsl:template match="isMemberOf "/>
Jonas Waeber's avatar
Jonas Waeber committed
378
379
380


</xsl:stylesheet>