wzb-oai_dc-2-xmlbundle.xslt 20.2 KB
Newer Older
Steinberg, Jan's avatar
Steinberg, Jan committed
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:cc="http://www.d-nb.de/standards/cc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:dcmitype="http://purl.org/dc/dcmitype/"
    xmlns:dcterms="http://purl.org/dc/terms/"
    xmlns:ddb="http://www.d-nb.de/standards/ddb/"
    xmlns:dini="http://www.d-nb.de/standards/xmetadissplus/type/"
    xmlns:doi="http://www.d-nb.de/standards/doi/"
    xmlns:hdl="http://www.d-nb.de/standards/hdl/"
    xmlns:mml="http://www.w3.org/1998/Math/MathML"
    xmlns:nlm="http://dtd.nlm.nih.gov/publishing/2.3"
    xmlns:oai="http://www.openarchives.org/OAI/2.0/"
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
    xmlns:pc="http://www.d-nb.de/standards/pc/"
    xmlns:thesis="http://www.ndltd.org/standards/metadata/etdms/1.0/"
    xmlns:urn="http://www.d-nb.de/standards/urn/"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xMetaDiss="http://www.d-nb.de/standards/xmetadissplus/"
    xmlns:xoai="http://www.lyncode.com/xoai"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:zoai="http://git.gesis.org/dda/zoai">
    
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>
    <!-- <xsl:copy-of select="."/>  -->
    <!-- <xsl:message terminate="no">here is some message for stderr, e.g. <xsl:value-of select='text()' /> </xsl:message> -->
    
    
    <!-- override default template -->
    <xsl:template match="*" />
    
    <xsl:template match="/">
        <xsl:element name="bundle">
            <xsl:element name="metadata">
                <xsl:apply-templates select="oai:OAI-PMH/oai:GetRecord/oai:record/oai:metadata/oai_dc:dc" />
            </xsl:element>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="oai:OAI-PMH/oai:GetRecord/oai:record/oai:metadata/oai_dc:dc">
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.rights.licence'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'3'"/>
        </xsl:call-template>
        
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.description.pubstatus'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'1'"/>
        </xsl:call-template>
        
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.publisher.country'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'DEU'"/>
        </xsl:call-template>
      
      <xsl:call-template name="new-metadatum">
        <xsl:with-param name="key" select="'ssoar.contributor.institution'"/>
        <xsl:with-param name="language" select="''"/>
        <xsl:with-param name="value" select="'WZB'"/>
      </xsl:call-template>
        
        <!-- <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'ssoar.urn.registration'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'false'"/>
        </xsl:call-template>-->
        
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.description.review'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'4'"/>
        </xsl:call-template>
  
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'internal.status'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'formal und inhaltlich fertig erschlossen'"/>
        </xsl:call-template>
        
        
        <!--xsl:apply-templates select="dc:type[@xml:lang='en-US']" /-->
        <xsl:apply-templates select="dc:title" />
        <xsl:apply-templates select="dc:description[1]" />
        <xsl:apply-templates select="dc:language" />
        <xsl:apply-templates select="dc:source[@xml:lang='de-DE']" />
91
92
93
        <xsl:apply-templates select="dc:identifier[matches(text(), '^http.*')]" />
        <xsl:apply-templates select="dc:identifier[matches(text(), '^Journal.*')]" />
        <xsl:apply-templates select="dc:identifier[matches(text(), '^doi.*')]" />
Steinberg, Jan's avatar
Steinberg, Jan committed
94
95
96
97
98
        <xsl:apply-templates select="dc:type" />
        <xsl:apply-templates select="dc:relation" />
        <xsl:apply-templates select="dc:creator" />
        <xsl:apply-templates select="dc:date" />
        <xsl:apply-templates select="dc:publisher" />
99
100
        <xsl:apply-templates select="dc:subject[starts-with(.,'ddc:')]" />
        <xsl:apply-templates select="dc:subject[not(starts-with(.,'ddc:'))]" />
Steinberg, Jan's avatar
Steinberg, Jan committed
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
    </xsl:template>
    
    <xsl:template match="dc:description[1]">
      <!--xsl:if test="position() = 1"-->
        <xsl:variable name="sanitizedLanguage" select="zoai:sanitizeLanguage( ../dc:language/text() )" />
        <xsl:call-template name="new-metadatum">
          <xsl:with-param name="key" select="'dc.description.abstract'"/>
          <xsl:with-param name="language" select="$sanitizedLanguage"/>
          <xsl:with-param name="value" select="normalize-space(replace(text(),'[‹›»«]','&quot;'))"/>
        </xsl:call-template>
      <!--/xsl:if-->
    </xsl:template>
    <xsl:template match="dc:date">
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.date.issued'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="substring(text(),1,4)"/>
        </xsl:call-template>
    </xsl:template>
    
    <xsl:template match="dc:creator">
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.contributor.author'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="text()"/>
        </xsl:call-template>
    </xsl:template>
    
    <xsl:template match="dc:relation">
      <xsl:if test="starts-with(., 'Series: ')">
        <xsl:call-template name="new-metadatum">
          <xsl:with-param name="key" select="'dc.source.series'"/>
          <xsl:with-param name="language" select="''"/>
          <xsl:with-param name="value" select="substring-before(substring-after(., 'Series: '), ' ;')"/>
        </xsl:call-template>
136
137
138
139
140
          <xsl:call-template name="new-metadatum">
              <xsl:with-param name="key" select="'dc.contributor.corporateeditor'"/>
              <xsl:with-param name="language" select="''"/>
              <xsl:with-param name="value" select="'381'"/>
          </xsl:call-template>
Steinberg, Jan's avatar
Steinberg, Jan committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
        <xsl:if test="contains(., ' ; ')">
          <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.source.volume'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="replace(substring-after(., ' ; '), 'No.','')"/>
          </xsl:call-template>
        </xsl:if>
      </xsl:if>
      
       
    </xsl:template>
    
    <xsl:template match="dc:language">
        <xsl:if test="position()=1">
        <xsl:variable name="sanitizedLanguage" select="zoai:sanitizeLanguage( text() )" />
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.language'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="$sanitizedLanguage"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    <xsl:template match="dc:identifier[matches(text(), '^http.*')]">
        <xsl:if test="not(contains(text(), 'handle'))">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.identifier.url'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="text()"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="contains(text(), 'handle')">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.identifier.handle'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="text()"/>
            </xsl:call-template>
        </xsl:if>
Steinberg, Jan's avatar
Steinberg, Jan committed
179
180
    </xsl:template>
    
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
    <xsl:template match="dc:identifier[matches(text(), '^doi.*')]">
        <xsl:choose>
            <xsl:when test="contains(.,'doi.org')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.identifier.doi'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="text()"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.identifier.doi'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="concat('https://doi.org/', substring-after(text(), 'doi:'))"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
    
    <xsl:template match="dc:identifier[matches(text(), '^Journal.*')]">
        <xsl:for-each select="tokenize(text(), ' ; ')">
            <xsl:if test="starts-with(., 'Journal: ')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.source.journal'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="normalize-space(substring-after(.,'Journal:'))"/>
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="starts-with(., 'ISSN: ')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.identifier.issn'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="normalize-space(substring-after(.,'ISSN:'))"/>
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="starts-with(., 'Volume: ')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.source.volume'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="normalize-space(substring-after(.,'Volume:'))"/>
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="starts-with(., 'Issue: ')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.source.issue'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="normalize-space(substring-after(.,'Issue:'))"/>
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="starts-with(., 'Pages: ')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.source.pageinfo'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="normalize-space(substring-after(.,'Pages:'))"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
Steinberg, Jan's avatar
Steinberg, Jan committed
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
    </xsl:template>
    
    <xsl:template match="dc:source[@xml:lang='de-DE']">
        <xsl:variable name="pageinfo" select="tokenize( text(),'; ' )[last()]" />
        <xsl:if test="$pageinfo != '' and matches($pageinfo, '^\d+(-\d+)?')">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.source.pageinfo'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="$pageinfo"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="$pageinfo != '' and matches($pageinfo, '^\w\d+(-\w\d+)?')">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.source.pageinfo'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="$pageinfo"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:variable name="issue" select="substring-before(substring-after(text(),'Nr. '),' ')" />
        <xsl:if test="$issue != '' and matches ($issue, '\d+')">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.source.issue'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="$issue"/>
            </xsl:call-template>
        </xsl:if>
        <xsl:variable name="issuetopic" select="substring-before(substring-after(text(),'): '),'; ')" />
        <xsl:if test="$issuetopic != ''">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.source.issuetopic'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="replace($issuetopic,'•',':')"/>
            </xsl:call-template>
        </xsl:if>
        
    </xsl:template>
    
    <xsl:template match="dc:type">
      <xsl:choose>
        <xsl:when test="starts-with(., 'doc-type')">
          <xsl:if test="contains(., 'workingPaper')">
            <xsl:call-template name="new-metadatum">
                <xsl:with-param name="key" select="'dc.type.stock'"/>
                <xsl:with-param name="language" select="''"/>
                <xsl:with-param name="value" select="'monograph'"/>
            </xsl:call-template>
            <xsl:call-template name="new-metadatum">
              <xsl:with-param name="key" select="'dc.type.document'"/>
              <xsl:with-param name="language" select="''"/>
              <xsl:with-param name="value" select="'3'"/>
            </xsl:call-template>
          </xsl:if>
291
292
293
294
295
296
297
298
299
300
301
302
            <xsl:if test="contains(., 'article')">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.type.stock'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="'article'"/>
                </xsl:call-template>
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.type.document'"/>
                    <xsl:with-param name="language" select="''"/>
                    <xsl:with-param name="value" select="'32'"/>
                </xsl:call-template>
            </xsl:if>
Steinberg, Jan's avatar
Steinberg, Jan committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.type.stock'"/>
            <xsl:with-param name="language" select="''"/>
            <xsl:with-param name="value" select="'monograph'"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
  <xsl:template match="dc:publisher">
    <xsl:call-template name="new-metadatum">
      <xsl:with-param name="key" select="'dc.publisher.city'"/>
      <xsl:with-param name="language" select="''"/>
      <xsl:with-param name="value" select="'Berlin'"/>
    </xsl:call-template>
  </xsl:template>
  
322
    <xsl:template match="dc:subject[starts-with(.,'ddc:')]">
Steinberg, Jan's avatar
Steinberg, Jan committed
323
324
    <xsl:if test="starts-with(.,'ddc:')">
      <xsl:call-template name="new-metadatum">
325
          <xsl:with-param name="key" select="'internal.identifier.ddc'"/>
Steinberg, Jan's avatar
Steinberg, Jan committed
326
327
328
329
330
        <xsl:with-param name="language" select="''"/>
        <xsl:with-param name="value" select="substring-after(., 'ddc:')"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
331
332
333
334
335
336
337
338
339
    
    <xsl:template match="dc:subject[not(starts-with(.,'ddc:'))]">
        <xsl:variable name="sanitizedMainLanguage" select="zoai:sanitizeLanguage( /oai:OAI-PMH/oai:GetRecord/oai:record/oai:metadata/oai_dc:dc/dc:language[1] )" />
        <xsl:call-template name="new-metadatum">
            <xsl:with-param name="key" select="'dc.subject.other'"/>
            <xsl:with-param name="language" select="$sanitizedMainLanguage"/>
            <xsl:with-param name="value" select="text()"/>
        </xsl:call-template>
    </xsl:template>
Steinberg, Jan's avatar
Steinberg, Jan committed
340
341
  
    <xsl:template match="dc:title">
342
        <!--xsl:variable name="sanitizedLanguage" select="zoai:sanitizeLanguage( @xml:lang )" /-->
Steinberg, Jan's avatar
Steinberg, Jan committed
343
344
345
        <xsl:variable name="sanitizedMainLanguage" select="zoai:sanitizeLanguage( /oai:OAI-PMH/oai:GetRecord/oai:record/oai:metadata/oai_dc:dc/dc:language[1] )" />
        
        <xsl:choose>
346
            <xsl:when test="string-length($sanitizedMainLanguage) > 0 and position() = 1">
Steinberg, Jan's avatar
Steinberg, Jan committed
347
348
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.title'"/>
349
350
                    <xsl:with-param name="language" select="$sanitizedMainLanguage"/>
                    <xsl:with-param name="value" select="normalize-space(replace(text(),'[‹›»«]','&quot;'))"/>
Steinberg, Jan's avatar
Steinberg, Jan committed
351
352
                </xsl:call-template>
            </xsl:when>
353
            <xsl:when test="$sanitizedMainLanguage = '' and position() = 1">
Steinberg, Jan's avatar
Steinberg, Jan committed
354
355
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.title'"/>
356
357
358
359
360
361
362
363
364
                    <xsl:with-param name="language" select="'de'"/>
                    <xsl:with-param name="value" select="normalize-space(replace(text(),'[‹›»«]','&quot;'))"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="$sanitizedMainLanguage = '' and position() > 1">
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.title.alternative'"/>
                    <xsl:with-param name="language" select="'de'"/>
                    <xsl:with-param name="value" select="normalize-space(replace(text(),'[‹›»«]','&quot;'))"/>
Steinberg, Jan's avatar
Steinberg, Jan committed
365
366
367
368
369
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="new-metadatum">
                    <xsl:with-param name="key" select="'dc.title.alternative'"/>
370
                    <xsl:with-param name="language" select="$sanitizedMainLanguage"/>
Steinberg, Jan's avatar
Steinberg, Jan committed
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
                    <xsl:with-param name="value" select="normalize-space(replace(text(),'[‹›»«]','&quot;'))"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
    
    
    <xsl:template name="new-metadatum">
        <xsl:param name="key" />
        <xsl:param name="language" />
        <xsl:param name="value" />
        <xsl:element name="metadatum">
            
            <xsl:element name="key">
                <xsl:value-of select="$key" />
            </xsl:element>
            
            <xsl:if test="$language != ''">
                <xsl:variable name="sanitizedLanguage" select="zoai:sanitizeLanguage($language)" />
                
                <xsl:element name="language">
                    <xsl:value-of select="$sanitizedLanguage" />
                </xsl:element>
            </xsl:if>
            
            <xsl:element name="value">
                <xsl:value-of select="$value" />
            </xsl:element>
            
        </xsl:element>
    </xsl:template>
    
    <xsl:function name="zoai:sanitizeLanguage">
        <xsl:param name="inputLanguage" />
        <xsl:choose>
            <xsl:when test="$inputLanguage = 'ger' or $inputLanguage = 'DE' or $inputLanguage = 'de-DE' or $inputLanguage = 'deu'">
                <xsl:value-of select="'de'" />
            </xsl:when>
            <xsl:when test="$inputLanguage = 'eng' or $inputLanguage = 'EN' or $inputLanguage = 'en-US' or $inputLanguage = 'en-GB'">
                <xsl:value-of select="'en'" />
            </xsl:when>
            <xsl:when test="$inputLanguage = 'ukr' or $inputLanguage = 'uk-UA'">
                <xsl:value-of select="'uk'" />
            </xsl:when>
            <xsl:when test="$inputLanguage = 'rus' or $inputLanguage = 'ru-RU'">
                <xsl:value-of select="'ru'" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$inputLanguage" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:function>
</xsl:stylesheet>