-
Notifications
You must be signed in to change notification settings - Fork 17
/
slurp_all_MODS_to_solr.xslt
371 lines (339 loc) · 16 KB
/
slurp_all_MODS_to_solr.xslt
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
371
<?xml version="1.0" encoding="UTF-8"?>
<!-- Basic MODS -->
<xsl:stylesheet version="1.0"
xmlns:java="http://xml.apache.org/xalan/java"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foxml="info:fedora/fedora-system:def/foxml#"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="mods java">
<!-- <xsl:include href="/usr/local/fedora/tomcat/webapps/fedoragsearch/WEB-INF/classes/config/index/FgsIndex/islandora_transforms/manuscript_finding_aid.xslt"/> -->
<xsl:include href="/usr/local/fedora/tomcat/webapps/fedoragsearch/WEB-INF/classes/fgsconfigFinal/index/FgsIndex/islandora_transforms/manuscript_finding_aid.xslt"/>
<xsl:include href="/usr/local/fedora/tomcat/webapps/fedoragsearch/WEB-INF/classes/fgsconfigFinal/index/FgsIndex/islandora_transforms/slurp_MODS_fields_with_ALL_suffix_to_solr.xslt"/>
<!-- HashSet to track single-valued fields. -->
<xsl:variable name="single_valued_hashset" select="java:java.util.HashSet.new()"/>
<xsl:template match="foxml:datastream[@ID='MODS']/foxml:datastreamVersion[last()]" name="index_MODS">
<xsl:param name="content"/>
<xsl:param name="prefix"></xsl:param>
<xsl:param name="suffix">ms</xsl:param>
<!-- Clearing hash in case the template is ran more than once. -->
<xsl:variable name="return_from_clear" select="java:clear($single_valued_hashset)"/>
<xsl:apply-templates mode="slurping_MODS" select="$content//mods:mods[1]">
<xsl:with-param name="prefix" select="$prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="pid" select="../../@PID"/>
<xsl:with-param name="datastream" select="../@ID"/>
</xsl:apply-templates>
<xsl:apply-templates mode="slurp_all_suffix" select="$content//mods:mods[1]"/>
</xsl:template>
<!-- Handle dates. -->
<xsl:template match="mods:*[(@type='date') or (contains(translate(local-name(), 'D', 'd'), 'date'))][normalize-space(text())]" mode="slurping_MODS">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:variable name="rawTextValue" select="normalize-space(text())"/>
<xsl:variable name="textValue">
<xsl:call-template name="get_ISO8601_date">
<xsl:with-param name="date" select="$rawTextValue"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
</xsl:call-template>
</xsl:variable>
<!-- Use attributes in field name. -->
<xsl:variable name="this_prefix">
<xsl:value-of select="$prefix"/>
<xsl:for-each select="@*">
<xsl:sort select="concat(local-name(), namespace-uri(self::node()))"/>
<xsl:value-of select="local-name()"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="translate(., ' ', '_')"/>
<xsl:text>_</xsl:text>
</xsl:for-each>
</xsl:variable>
<!-- Prevent multiple generating multiple instances of single-valued fields
by tracking things in a HashSet -->
<xsl:variable name="field_name" select="normalize-space(concat($this_prefix, local-name()))"/>
<!-- The method java.util.HashSet.add will return false when the value is
already in the set. -->
<xsl:if test="java:add($single_valued_hashset, $field_name)">
<xsl:if test="not(normalize-space($textValue)='')">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($field_name, '_dt')"/>
</xsl:attribute>
<xsl:value-of select="$textValue"/>
</field>
</xsl:if>
<xsl:if test="not(normalize-space($rawTextValue)='')">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($field_name, '_s')"/>
</xsl:attribute>
<xsl:value-of select="$rawTextValue"/>
</field>
</xsl:if>
</xsl:if>
<xsl:if test="not(normalize-space($textValue)='')">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($prefix, local-name(), '_mdt')"/>
</xsl:attribute>
<xsl:value-of select="$textValue"/>
</field>
</xsl:if>
<xsl:if test="not(normalize-space($rawTextValue)='')">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($prefix, local-name(), '_ms')"/>
</xsl:attribute>
<xsl:value-of select="$rawTextValue"/>
</field>
</xsl:if>
</xsl:template>
<!-- Avoid using text alone. -->
<xsl:template match="text()" mode="slurping_MODS"/>
<!-- Build up the list prefix with the element context. -->
<xsl:template match="*" mode="slurping_MODS">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz_'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ '" />
<xsl:variable name="this_prefix">
<xsl:value-of select="concat($prefix, local-name(), '_')"/>
<xsl:if test="@type">
<xsl:value-of select="concat(translate(@type, ' ', '_'), '_')"/>
</xsl:if>
</xsl:variable>
<xsl:call-template name="mods_language_fork">
<xsl:with-param name="prefix" select="$this_prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="normalize-space(text())"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
</xsl:call-template>
</xsl:template>
<!--
The "eventType" attribute was introduce with MODS 3.5... Let's start
exposing it for use.
-->
<xsl:template match="mods:originInfo" mode="slurping_MODS">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz_'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ '" />
<xsl:call-template name="mods_eventType_fork">
<xsl:with-param name="prefix" select="concat($prefix, local-name(), '_')"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="normalize-space(text())"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
</xsl:call-template>
</xsl:template>
<!-- Intercept names with role terms, so we can create copies of the fields
including the role term in the name of generated fields. (Hurray, additional
specificity!) -->
<xsl:template match="mods:name[mods:role/mods:roleTerm]" mode="slurping_MODS">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz_'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ '" />
<xsl:variable name="base_prefix">
<xsl:value-of select="concat($prefix, local-name(), '_')"/>
<xsl:if test="@type">
<xsl:value-of select="concat(translate(@type, ' ', '_'), '_')"/>
</xsl:if>
</xsl:variable>
<xsl:for-each select="mods:role/mods:roleTerm">
<xsl:variable name="this_prefix" select="concat($base_prefix, translate(normalize-space(.), $uppercase, $lowercase), '_')"/>
<xsl:call-template name="mods_language_fork">
<xsl:with-param name="prefix" select="$this_prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="normalize-space(text())"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="../.."/>
</xsl:call-template>
</xsl:for-each>
<xsl:call-template name="mods_language_fork">
<xsl:with-param name="prefix" select="$base_prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="normalize-space(text())"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
</xsl:call-template>
</xsl:template>
<!-- Fields are duplicated for authority because searches across authorities are common. -->
<xsl:template name="mods_authority_fork">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="value"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:param name="node" select="current()"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz_'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ '" />
<xsl:call-template name="general_mods_field">
<xsl:with-param name="prefix" select="$prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
<!-- Fields are duplicated for authority because searches across authorities are common. -->
<xsl:if test="@authority">
<xsl:call-template name="general_mods_field">
<xsl:with-param name="prefix" select="concat($prefix, 'authority_', translate(@authority, $uppercase, $lowercase), '_')"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Fork on eventType to preserve legacy field names. -->
<xsl:template name="mods_eventType_fork">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="value"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:param name="node" select="current()"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz_'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ '" />
<xsl:call-template name="mods_language_fork">
<xsl:with-param name="prefix" select="$prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
<xsl:if test="@eventType">
<xsl:call-template name="mods_language_fork">
<xsl:with-param name="prefix" select="concat($prefix, 'eventType_', translate(@eventType, $uppercase, $lowercase), '_')"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Want to include language in field names. -->
<xsl:template name="mods_language_fork">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="value"/>
<xsl:param name="pid">not provided</xsl:param>
<xsl:param name="datastream">not provided</xsl:param>
<xsl:param name="node" select="current()"/>
<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz_'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ '" />
<xsl:call-template name="mods_authority_fork">
<xsl:with-param name="prefix" select="$prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
<!-- Fields are duplicated for authority because searches across authorities are common. -->
<xsl:if test="@lang">
<xsl:call-template name="mods_authority_fork">
<xsl:with-param name="prefix" select="concat($prefix, 'lang_', translate(@lang, $uppercase, $lowercase), '_')"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:if>
<!-- Look for @xml:lang tags too. -->
<xsl:if test="@xml:lang">
<xsl:call-template name="mods_authority_fork">
<xsl:with-param name="prefix" select="concat($prefix, 'lang_', translate(@xml:lang, $uppercase, $lowercase), '_')"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="value" select="$value"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
<xsl:with-param name="node" select="$node"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Handle the actual indexing of the majority of MODS elements, including
the recursive step of kicking off the indexing of subelements. -->
<xsl:template name="general_mods_field">
<xsl:param name="prefix"/>
<xsl:param name="suffix"/>
<xsl:param name="value"/>
<xsl:param name="pid"/>
<xsl:param name="datastream"/>
<xsl:param name="node" select="current()"/>
<xsl:if test="$value">
<field>
<xsl:attribute name="name">
<xsl:choose>
<!-- Try to create a single-valued version of each field (if one
does not already exist, that is). -->
<!-- XXX: We make some assumptions about the schema here...
Primarily, _s getting copied to the same places as _ms. -->
<xsl:when test="$suffix='ms' and java:add($single_valued_hashset, string($prefix))">
<xsl:value-of select="concat($prefix, 's')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($prefix, $suffix)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="$value"/>
</field>
</xsl:if>
<xsl:if test="normalize-space($node/@authorityURI)">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($prefix, 'authorityURI_', $suffix)"/>
</xsl:attribute>
<xsl:value-of select="$node/@authorityURI"/>
</field>
</xsl:if>
<xsl:if test="normalize-space($node/@valueURI)">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($prefix, 'valueURI_', $suffix)"/>
</xsl:attribute>
<xsl:value-of select="$node/@valueURI"/>
</field>
</xsl:if>
<xsl:if test="normalize-space($node/@xlink:href)">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($prefix, 'xlinkhref_', $suffix)"/>
</xsl:attribute>
<xsl:value-of select="$node/@xlink:href"/>
</field>
</xsl:if>
<xsl:if test="normalize-space($node/@displayLabel)">
<field>
<xsl:attribute name="name">
<xsl:value-of select="concat($prefix, 'displayLabel_', $suffix)"/>
</xsl:attribute>
<xsl:value-of select="$node/@displayLabel"/>
</field>
</xsl:if>
<xsl:apply-templates select="$node/*" mode="slurping_MODS">
<xsl:with-param name="prefix" select="$prefix"/>
<xsl:with-param name="suffix" select="$suffix"/>
<xsl:with-param name="pid" select="$pid"/>
<xsl:with-param name="datastream" select="$datastream"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>