-
Notifications
You must be signed in to change notification settings - Fork 0
/
marcxml2tei-1.0.xsl
370 lines (333 loc) · 16.5 KB
/
marcxml2tei-1.0.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
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:hal="http://hal.archives-ouvertes.fr/" xsi:schemaLocation="http://www.tei-c.org/ns/1.0 http://api.archives-ouvertes.fr/documents/aofr-sword.xsd"
xmlns:ext="http://exslt.org/common">
<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes" />
<!-- Liste des codes diplôme : https://api.archives-ouvertes.fr/ref/metadataList/?q=metaName_s:dumas_degreeType&rows=70 -->
<xsl:param name="degreeCode" select="'23'" />
<!-- Lien vers le fichier PDF. Peut prendre la forme d'un lien ftp -->
<xsl:param name="fileLocation" select="''" />
<xsl:variable name="IdRefBaseUrl" select="'https://www.idref.fr/'" />
<xsl:template name="tei" match="record">
<TEI>
<text>
<body>
<listBibl>
<biblFull>
<!-- <xsl:call-template name="editionStmt" /> -->
<xsl:call-template name="notesStmt" />
<sourceDesc>
<biblStruct>
<xsl:call-template name="analytic" />
<xsl:call-template name="monogr" />
</biblStruct>
</sourceDesc>
<xsl:call-template name="profileDesc" />
</biblFull>
</listBibl>
</body>
</text>
</TEI>
</xsl:template>
<!-- <xsl:template name="editionStmt">
<editionStmt>
<edition>
<date type="whenWritten">
<xsl:value-of select="datafield[@tag = '328']/subfield[@code = 'd']" />
</date>
<xsl:if test="$fileLocation">
<ref type="file" subtype="author" n="1" target="{$fileLocation}">
<xsl:if test="$embargoDate">
<date notBefore="{$embargoDate}" />
</xsl:if>
</ref>
</xsl:if>
</edition>
</editionStmt>
</xsl:template> -->
<xsl:template name="notesStmt">
<notesStmt>
<note type="audience" n="3" />
<!--<note type="degree" n="{$degreeCode}" />-->
</notesStmt>
</xsl:template>
<xsl:template name="analytic">
<analytic>
<xsl:call-template name="title" />
<xsl:call-template name="author" />
</analytic>
</xsl:template>
<xsl:template name="title">
<xsl:variable name="mainTitleLang">
<xsl:variable name="mainTitleLang639_2">
<xsl:choose>
<xsl:when test="count(/record/datafield[@tag='101']/subfield[@code='a'])=1">
<xsl:value-of select="/record/datafield[@tag='101']//subfield[@code='a'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>fr</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="codeLangue">
<xsl:with-param name="code" select="$mainTitleLang639_2"/>
</xsl:call-template>
</xsl:variable>
<title xml:lang='{$mainTitleLang}'>
<xsl:call-template name="joinTitleElements">
<xsl:with-param name="titles" select="datafield[@tag = '200']/subfield[@code = 'a']" />
<xsl:with-param name="subtitles" select="datafield[@tag = '200']/subfield[@code = 'e']" />
</xsl:call-template>
</title>
<xsl:for-each select="datafield[@tag = '541']">
<xsl:if test="./subfield[@code = 'a' or @code = 'e']">
<xsl:variable name="titleLang">
<xsl:call-template name="codeLangue">
<xsl:with-param name="code" select="./subfield[@code = 'z']"/>
</xsl:call-template>
</xsl:variable>
<title xml:lang="{$titleLang}">
<xsl:call-template name="joinTitleElements">
<xsl:with-param name="titles" select="./subfield[@code = 'a']"/>
<xsl:with-param name="subtitles" select="./subfield[@code = 'e']" />
</xsl:call-template>
</title>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="author">
<!-- for-each is used to sets the current node context -->
<xsl:for-each select="datafield[@tag = '700'][subfield[@code = '4'] = '070']">
<author role="aut">
<persName>
<forename type="first">
<xsl:value-of select="subfield[@code = 'b']" />
</forename>
<surname>
<xsl:value-of select="subfield[@code = 'a']" />
</surname>
</persName>
<xsl:if test="subfield[@code = '3']">
<idno type="IdRef">
<xsl:value-of select="concat($IdRefBaseUrl, subfield[@code = '3'])" />
</idno>
</xsl:if>
</author>
</xsl:for-each>
</xsl:template>
<xsl:template name="monogr">
<monogr>
<!-- <settlement>
<xsl:value-of select="datafield[@tag = '711' and subfield[@code = '4'] = '295' ]/subfield[@code = 'c']" />
</settlement> -->
<imprint>
<xsl:if test="(datafield[@tag = '307']/subfield[@code = ('a') and contains(., 'impression du document génère')])[1]">
<biblScope unit="pp">
<!-- suppression de la chaine de caractères : "L'impression du document génère" -->
<xsl:value-of select="translate(translate(substring ((datafield[@tag = '307']/subfield[@code = ('a') and contains(., 'impression du document génère')])[1], 33), 'p. ', ''), translate(.,'0123456789',''), '')"/>
</biblScope>
</xsl:if>
<date type="dateDefended">
<xsl:value-of select="(datafield[@tag = '328']/subfield[@code = ('d')])[1]" />
</date>
</imprint>
<xsl:if test="datafield[@tag = '711'][subfield[@code = '4'] = '295']">
<authority type="institution">
<xsl:value-of select="datafield[@tag = '711']/subfield[@code = 'a']" />
</authority>
</xsl:if>
<xsl:for-each
select="datafield[@tag='701'][subfield[@code='4']/text()='727' or subfield[@code='4']/text()='003']">
<authority type="supervisor">
<xsl:value-of select="normalize-space(concat(subfield[@code = 'b'], ' ', subfield[@code = 'a']))" />
</authority>
</xsl:for-each>
<xsl:call-template name="jury"/>
</monogr>
</xsl:template>
<xsl:template name="profileDesc">
<profileDesc>
<xsl:variable name="valLangue102">
<xsl:value-of select="translate(datafield[@tag = '102']/subfield[@code = 'a'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')" />
</xsl:variable>
<xsl:if test="$valLangue102 != null and $valLangue102 != ''">
<langUsage>
<language ident="{$valLangue102}" />
</langUsage>
</xsl:if>
<textClass>
<xsl:call-template name="keywords" />
<xsl:for-each select="datafield[@tag = '686'][subfield[@code = '2'] = 'TEF']/subfield[@code = 'a' or @code = 'HALDOMAIN']">
<xsl:variable name="oai">
<xsl:call-template name="codeOai">
<xsl:with-param name="code" select="normalize-space(text())"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$oai != ''">
<classCode scheme="halDomain" n="{$oai}" />
</xsl:if>
</xsl:for-each>
<classCode scheme="halTypology" n="MEM" />
</textClass>
<xsl:call-template name="abstract" />
</profileDesc>
</xsl:template>
<xsl:template name="keywords">
<xsl:variable name="keywords" select="datafield[@tag = '600' or @tag = '601' or @tag = '602' or @tag = '604' or @tag = '605' or @tag = '606' or @tag = '607' or @tag = '608' or @tag = '610']"/>
<xsl:if test="$keywords">
<keywords scheme="author">
<xsl:for-each select="$keywords">
<xsl:variable name="keyword">
<xsl:choose>
<xsl:when test="self::node()[@tag = '600']">
<xsl:call-template name="R600">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '601']">
<xsl:call-template name="R601">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '602']">
<xsl:call-template name="R602">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '604']">
<xsl:call-template name="R604">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '605']">
<xsl:call-template name="R605">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '606']">
<xsl:call-template name="R606">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '607']">
<xsl:call-template name="R607">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
<xsl:when test="self::node()[@tag = '608']">
<xsl:call-template name="R608">
<xsl:with-param name="field" select="." />
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="$keyword != ''">
<term xml:lang="fr">"<xsl:value-of select="$keyword"/>"</term>
</xsl:if>
<xsl:if test="self::node()[@tag = '610']">
<xsl:for-each select="subfield[@code = 'a']">
<xsl:if test=".!= ''">
<term xml:lang="fr">"<xsl:value-of select="."/>"</term>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</keywords>
</xsl:if>
</xsl:template>
<xsl:template name="abstract">
<xsl:for-each select="datafield[@tag = '330']/subfield[@code = 'a']">
<xsl:variable name="abstractIndex" select="position()"/>
<xsl:variable name="abstractLang">
<xsl:call-template name="codeLangue">
<xsl:with-param name="code" select="//datafield[@tag='101']/subfield[@code='d'][$abstractIndex]"/>
</xsl:call-template>
</xsl:variable>
<abstract xml:lang="{$abstractLang}">
<xsl:value-of select="." />
</abstract>
</xsl:for-each>
</xsl:template>
<xsl:template name="president_jury">
<xsl:for-each select="datafield[@tag='701'][subfield[@code='4']/text()='956']">
<xsl:call-template name="format_jury_member">
<xsl:with-param name="jury_member"><xsl:value-of select="."/></xsl:with-param>
<xsl:with-param name="role">Président</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="rapporteurs_jury">
<xsl:for-each select="datafield[@tag='701'][subfield[@code='4']/text()='958']">
<xsl:call-template name="format_jury_member">
<xsl:with-param name="jury_member"><xsl:value-of select="."/></xsl:with-param>
<xsl:with-param name="role">Rapporteur</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="membres_jury">
<xsl:for-each select="datafield[@tag='701'][subfield[@code='4']/text()='555']">
<xsl:call-template name="format_jury_member">
<xsl:with-param name="jury_member"><xsl:value-of select="."/></xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="format_jury_member">
<xsl:param name="jury_member"/>
<xsl:param name="role"/>
<xsl:variable name="prenom_nom" select="concat(subfield[@code='b'], ' ', subfield[@code='a'])"/>
<xsl:variable name="formated_role">
<xsl:if test="$role">[<xsl:value-of select="$role"/>]</xsl:if>
</xsl:variable>
<xsl:if test="$prenom_nom">
<authority type="jury">
<xsl:value-of select="normalize-space(concat($prenom_nom, ' ', $formated_role))"/>
</authority>
</xsl:if>
</xsl:template>
<xsl:template name="jury">
<xsl:call-template name="president_jury"/>
<xsl:call-template name="rapporteurs_jury"/>
<xsl:call-template name="membres_jury"/>
</xsl:template>
<!-- Joint le titre et les sous-titres selon la syntaxe suivante : `Titre : Sous titre 1. Sous titre 2` -->
<xsl:template name="joinTitleElements">
<xsl:param name="titles" />
<xsl:param name="subtitles" />
<!-- Joint les titres par ; -->
<xsl:for-each select="$titles">
<xsl:if test="position() > 1">
<xsl:text> ; </xsl:text>
</xsl:if>
<xsl:call-template name="removeTrailingPunctuation">
<xsl:with-param name="input" select="."/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="$subtitles">
<xsl:if test="position() = 1">
<xsl:text> : </xsl:text>
</xsl:if>
<xsl:if test="position() > 1">
<xsl:text>. </xsl:text>
</xsl:if>
<xsl:call-template name="removeTrailingPunctuation">
<xsl:with-param name="input" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="removeTrailingPunctuation">
<xsl:param name="input" />
<xsl:variable name="currentValue" select="normalize-space($input)" />
<xsl:variable name="lastChar" select="normalize-space(substring($currentValue, string-length($currentValue)))" />
<xsl:choose>
<xsl:when test="$lastChar = '/' or $lastChar = ';' or $lastChar = ',' or $lastChar = '.'">
<xsl:value-of select="normalize-space(substring($currentValue, 1, string-length($currentValue) - 1))" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$input" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>