forked from carakey/xml2csv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
claw_fields_tsv_maker.xsl
336 lines (301 loc) · 13.8 KB
/
claw_fields_tsv_maker.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.loc.gov/mods/v3"
xmlns="http://www.loc.gov/mods/v3"
xmlns:mods="http://www.loc.gov/mods/v3"
version="2.0"
>
<xsl:output method="text"/>
<!-- Sets the field separator with a variable;
if necessary, it can be reset throughout -->
<xsl:variable name="separator" select="'	'"/>
<xsl:template match="/">
<xsl:call-template name="headerRow"/>
<xsl:apply-templates select="modsCollection/mods"/>
</xsl:template>
<!-- Begin header row -->
<!--
Uses the mappings from the CLAW MIG Spring Prep Mapping spreadsheet, at
https://docs.google.com/spreadsheets/d/18u2qFJ014IIxlVpM3JXfDEFccwBZcoFsjbBGpvL0jJI/edit#gid=0.
The mapped XPaths are used to create column headers.
-->
<xsl:template name="headerRow">
<xsl:text>7.X PID</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>titleInfo[not(@type)]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>titleInfo[@type='translated'] [[@xml:lang]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>titleInfo[@type='alternative' or @type='abbreviated' or @type='uniform']</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>personal name/namePart[not(@type)] or name/displayForm [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>personal name/namePart[@type] [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>corporate name/namePart[not(@type)] or name/displayForm [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>corporate name/namePart[@type] [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>conference name/namePart[not(@type)] or name/displayForm [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>conference name/namePart[@type] [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>family name/namePart[not(@type)] or name/displayForm [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>family name/namePart[@type] [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>untyped name/namePart[not(@type)] or name/displayForm [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>untyped name/namePart[@type] [[role]]</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>identifier</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>accessCondition</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>originInfo/dateOther</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>originInfo/dateIssued</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>originInfo/dateCreated</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>physicalDescription/extent</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>typeOfResource</xsl:text>
<xsl:value-of select="$separator"/>
<xsl:text>physicalDescription/internetMediaType</xsl:text>
<!-- New line for next record -->
<xsl:text>
</xsl:text>
</xsl:template>
<!-- End header row -->
<!-- Begin building record rows, one row per <mods> element in source document -->
<xsl:template match="mods">
<!-- Cell value for 7.X PID -->
<xsl:for-each select="identifier[@displayLabel='7.X PID']">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Main Title -->
<xsl:for-each select="titleInfo[not(@type)]">
<xsl:call-template name="titleInfo"/>
<xsl:if test="position()!=last()">
<xsl:text>||</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Translated Title;
Value of @xml:lang in double square brackets. -->
<xsl:for-each select="titleInfo[@type='translated']">
<xsl:call-template name="titleInfo"/>
<xsl:if test="@xml:lang">
<xsl:text> [[xml:lang=</xsl:text>
<xsl:value-of select="@xml:lang"/>
<xsl:text>]]</xsl:text>
</xsl:if>
<xsl:if test="position()!=last()">
<xsl:text>||</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Alternative Title -->
<xsl:for-each select="titleInfo[@type='alternative' or @type='abbreviated' or @type='uniform']">
<xsl:call-template name="titleInfo"/>
<xsl:if test="position()!=last()">
<xsl:text>||</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Simple Personal Name -->
<xsl:for-each select="name[@type='personal'][displayForm or namePart[not(@type)]]">
<xsl:call-template name="simpleName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Compound Personal Name -->
<xsl:for-each select="name[@type='personal'][namePart[@type]]">
<xsl:call-template name="compoundName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Simple Corporate Name -->
<xsl:for-each select="name[@type='corporate'][displayForm or namePart[not(@type)]]">
<xsl:call-template name="simpleName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Compound Corporate Name -->
<xsl:for-each select="name[@type='corporate'][namePart[@type]]">
<xsl:call-template name="compoundName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Simple Conference Name -->
<xsl:for-each select="name[@type='conference'][displayForm or namePart[not(@type)]]">
<xsl:call-template name="simpleName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Compound Conference Name -->
<xsl:for-each select="name[@type='conference'][namePart[@type]]">
<xsl:call-template name="compoundName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Simple Family Name -->
<xsl:for-each select="name[@type='family'][displayForm or namePart[not(@type)]]">
<xsl:call-template name="simpleName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Compound Family Name -->
<xsl:for-each select="name[@type='family'][namePart[@type]]">
<xsl:call-template name="compoundName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Simple Un-Typed Name -->
<xsl:for-each select="name[not(@type)][displayForm or namePart[not(@type)]]">
<xsl:call-template name="simpleName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Compound Un-Typed Name -->
<xsl:for-each select="name[not(@type)][namePart[@type]]">
<xsl:call-template name="compoundName"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Identifier;
Omits the 7.x PID identifier created by mods_xml_merge.xsl -->
<xsl:for-each select="identifier[not(@displayLabel='7.X PID')]">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Rights -->
<xsl:for-each select="accessCondition">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Date Other -->
<xsl:for-each select="originInfo/dateOther">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Date Issued] -->
<xsl:for-each select="originInfo/dateIssued">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Date Created] -->
<xsl:for-each select="originInfo/dateCreated">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Extent] -->
<xsl:for-each select="physicalDescription/extent">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Type Of Resource] -->
<xsl:for-each select="typeOfResource">
<xsl:call-template name="cell"/>
</xsl:for-each>
<xsl:value-of select="$separator"/>
<!-- Cell value for Mime Type] -->
<xsl:for-each select="physicalDescription/internetMediaType">
<xsl:call-template name="cell"/>
</xsl:for-each>
<!-- New line for next record -->
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="cell">
<xsl:value-of select="normalize-space(.)"/>
<xsl:if test="position()!=last()">
<xsl:text>||</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="simpleName">
<xsl:choose>
<xsl:when test="displayForm">
<xsl:for-each select="displayForm">
<xsl:value-of select="normalize-space(.)"/>
<xsl:if test="position() != last()">
<xsl:text>. </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="namePart[not(@type)]">
<xsl:for-each select="namePart[not(@type)]">
<xsl:value-of select="normalize-space(.)"/>
<xsl:if test="position() != last()">
<xsl:text>. </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:when>
</xsl:choose>
<xsl:call-template name="role"/>
<xsl:if test="position() != last()">
<xsl:text>||</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="compoundName">
<xsl:for-each select="namePart[@type]">
<xsl:value-of select="normalize-space(.)"/>
<xsl:text> [[type=</xsl:text>
<xsl:value-of select="@type"/>
<xsl:text>]]</xsl:text>
</xsl:for-each>
<xsl:call-template name="role"/>
<xsl:if test="position() != last()">
<xsl:text>||</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="role">
<xsl:choose>
<xsl:when test="role">
<xsl:choose>
<xsl:when test="role/roleTerm[@authority='marcrelator']">
<xsl:text> [[marcrelators=</xsl:text>
<xsl:choose>
<xsl:when test="role/roleTerm[@authority='marcrelator'][@type='code']">
<xsl:value-of select="role/roleTerm[@authority='marcrelator'][@type='code']"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>NULL</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>/</xsl:text>
<xsl:choose>
<xsl:when test="role/roleTerm[@authority='marcrelator'][@type='text']">
<xsl:value-of select="role/roleTerm[@authority='marcrelator'][@type='text']"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>NULL</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>]]</xsl:text>
</xsl:when>
<!-- If the role does not have marcrelators as its authority,
then supply role of Contributor -->
<xsl:otherwise>
<xsl:text> [[marcrelators=ctb/Contributor]]</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- If there is no role, then supply role of Contributor -->
<xsl:otherwise>
<xsl:text> [[marcrelators=ctb/Contributor]]</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="titleInfo">
<xsl:if test="nonSort">
<xsl:value-of select="normalize-space(nonSort)"/>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="normalize-space(title)"/>
<xsl:if test="subTitle">
<xsl:text>: </xsl:text>
<xsl:value-of select="normalize-space(subTitle)"/>
</xsl:if>
<xsl:if test="partName|partNumber">
<xsl:for-each select="partName|partNumber">
<xsl:text>. </xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:if test="position()=last()">
<xsl:text>.</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>