2 <xsl:stylesheet version=
"1.0"
3 xmlns:
marc=
"http://www.loc.gov/MARC21/slim"
4 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
5 xmlns:
xslo=
"http://www.w3.org/1999/XSL/TransformAlias"
6 xmlns:
z=
"http://indexdata.com/zebra-2.0"
7 xmlns:
kohaidx=
"http://www.koha-community.org/schemas/index-defs">
9 <xsl:namespace-alias stylesheet-prefix=
"xslo" result-prefix=
"xsl"/>
10 <xsl:output indent=
"yes" method=
"xml" version=
"1.0" encoding=
"UTF-8"/>
11 <!-- disable all default text node output -->
12 <xsl:template match=
"text()"/>
14 <!-- Keys on tags referenced in the index definitions -->
15 <xsl:key name=
"index_control_field_tag" match=
"kohaidx:index_control_field" use=
"@tag"/>
16 <xsl:key name=
"index_subfields_tag" match=
"kohaidx:index_subfields" use=
"@tag"/>
17 <xsl:key name=
"index_facet_tag" match=
"kohaidx:facet" use=
"@tag"/>
18 <xsl:key name=
"index_heading_tag" match=
"kohaidx:index_heading" use=
"@tag"/>
19 <xsl:key name=
"index_data_field_tag" match=
"kohaidx:index_data_field" use=
"@tag"/>
20 <xsl:key name=
"index_heading_conditional_tag" match=
"kohaidx:index_heading_conditional" use=
"@tag"/>
21 <xsl:key name=
"index_match_heading_tag" match=
"kohaidx:index_match_heading" use=
"@tag"/>
23 <xsl:template match=
"kohaidx:index_defs">
25 This file has been automatically generated from a Koha index definition file
26 with the stylesheet koha-indexdefs-to-zebra.xsl. Do not manually edit this file,
27 as it may be overwritten. To regenerate, edit the appropriate Koha index
28 definition file (probably something like {biblio,authority}-koha-indexdefs.xml) and run:
29 `xsltproc koha-indexdefs-to-zebra.xsl {biblio,authority}-koha-indexdefs.xml
>
30 {biblio,authority}-zebra-indexdefs.xsl` (substituting the appropriate file names).
32 <xslo:stylesheet version=
"1.0">
33 <xslo:output indent=
"yes" method=
"xml" version=
"1.0" encoding=
"UTF-8"/>
34 <xslo:template match=
"text()"/>
35 <xslo:template match=
"text()" mode=
"index_subfields"/>
36 <xslo:template match=
"text()" mode=
"index_data_field"/>
37 <xslo:template match=
"text()" mode=
"index_facets"/>
38 <xslo:template match=
"text()" mode=
"index_heading"/>
39 <xslo:template match=
"text()" mode=
"index_heading_conditional"/>
40 <xslo:template match=
"text()" mode=
"index_match_heading"/>
41 <xslo:template match=
"text()" mode=
"index_subject_thesaurus"/>
42 <xslo:template match=
"text()" mode=
"index_sort_tit"/>
43 <xslo:template match=
"/">
44 <xslo:if test=
"marc:collection">
46 <xslo:apply-templates select=
"marc:collection/marc:record"/>
49 <xslo:if test=
"marc:record">
50 <xslo:apply-templates select=
"marc:record"/>
54 <xslo:template match=
"marc:record">
55 <xslo:variable name=
"idfield">
56 <xsl:attribute name=
"select">normalize-space(
<xsl:value-of select=
"//kohaidx:id"/>)
</xsl:attribute>
58 <z:record type=
"update">
59 <xslo:attribute name=
"z:id"><xslo:value-of select=
"$idfield"/></xslo:attribute>
60 <xslo:apply-templates/>
61 <xslo:apply-templates mode=
"index_subfields"/>
62 <xslo:apply-templates mode=
"index_data_field"/>
63 <xslo:apply-templates mode=
"index_facets"/>
64 <xslo:apply-templates mode=
"index_heading"/>
65 <xslo:apply-templates mode=
"index_heading_conditional"/>
66 <xslo:apply-templates mode=
"index_match_heading"/>
67 <xslo:apply-templates mode=
"index_subject_thesaurus"/>
68 <xslo:apply-templates mode=
"index_all"/>
69 <xslo:apply-templates mode=
"index_sort_tit"/>
73 <xsl:call-template name=
"handle-index-leader"/>
74 <xsl:call-template name=
"handle-index-control-field"/>
75 <xsl:call-template name=
"handle-index-subfields"/>
76 <xsl:call-template name=
"handle-index-data-field"/>
77 <xsl:call-template name=
"handle-index-facets"/>
78 <xsl:call-template name=
"handle-index-heading"/>
79 <xsl:call-template name=
"handle-index-heading-conditional"/>
80 <xsl:call-template name=
"handle-index-match-heading"/>
81 <xsl:apply-templates/>
82 <xslo:template mode=
"index_all" match=
"text()">
83 <z:index name=
"Any:w Any:p">
84 <xslo:value-of select=
"."/>
87 <xslo:template mode=
"index_sort_tit" match=
"marc:datafield[@tag='245']">
88 <xslo:variable name=
"chop">
90 <xslo:when test=
"not(number(@ind2))">0</xslo:when>
91 <xslo:otherwise><xslo:value-of select=
"number(@ind2)"/></xslo:otherwise>
94 <z:index name=
"Title:s">
95 <xslo:value-of select=
"substring(marc:subfield[@code='a'], $chop+1)"/>
98 <xslo:template name=
"chopPunctuation">
99 <xslo:param name=
"chopString"/>
100 <xslo:variable name=
"length" select=
"string-length($chopString)"/>
102 <xslo:when test=
"$length=0"/>
103 <xslo:when test=
"contains('-,.:=;!%/', substring($chopString,$length,1))">
104 <xslo:call-template name=
"chopPunctuation">
105 <xslo:with-param name=
"chopString" select=
"substring($chopString,1,$length - 1)"/>
106 </xslo:call-template>
108 <xslo:when test=
"not($chopString)"/>
109 <xslo:otherwise><xslo:value-of select=
"$chopString"/></xslo:otherwise>
111 <xslo:text> </xslo:text>
116 <!-- map kohaidx:var to stylesheet variables -->
117 <xsl:template match=
"kohaidx:var">
119 <xsl:attribute name=
"name"><xsl:value-of select=
"@name"/></xsl:attribute>
120 <xsl:value-of select=
"."/>
124 <xsl:template match=
"kohaidx:index_subject_thesaurus">
125 <xsl:variable name=
"tag"><xsl:value-of select=
"@tag"/></xsl:variable>
126 <xsl:variable name=
"offset"><xsl:value-of select=
"@offset"/></xsl:variable>
127 <xsl:variable name=
"length"><xsl:value-of select=
"@length"/></xsl:variable>
128 <xsl:variable name=
"detail_tag"><xsl:value-of select=
"@detail_tag"/></xsl:variable>
129 <xsl:variable name=
"detail_subfields"><xsl:value-of select=
"@detail_subfields"/></xsl:variable>
130 <xsl:variable name=
"indexes">
131 <xsl:call-template name=
"get-target-indexes"/>
133 <xslo:template mode=
"index_subject_thesaurus">
134 <xsl:attribute name=
"match">
135 <xsl:text>marc:controlfield[@tag='
</xsl:text>
136 <xsl:value-of select=
"$tag"/>
137 <xsl:text>']
</xsl:text>
139 <xslo:variable name=
"thesaurus_code1">
140 <xsl:attribute name=
"select">
141 <xsl:text>substring(.,
</xsl:text>
142 <xsl:value-of select=
"$offset + 1" />
143 <xsl:text>,
</xsl:text>
144 <xsl:value-of select=
"$length" />
145 <xsl:text>)
</xsl:text>
148 <xsl:variable name=
"alt_select">
149 <xsl:text>//marc:datafield[@tag='
</xsl:text>
150 <xsl:value-of select=
"$detail_tag"/>
151 <xsl:text>']/marc:subfield[@code='
</xsl:text>
152 <xsl:value-of select=
"$detail_subfields"/>
153 <xsl:text>']
</xsl:text>
155 <xslo:variable name=
"full_thesaurus_code">
157 <xslo:when test=
"$thesaurus_code1 = 'a'"><xslo:text>lcsh
</xslo:text></xslo:when>
158 <xslo:when test=
"$thesaurus_code1 = 'b'"><xslo:text>lcac
</xslo:text></xslo:when>
159 <xslo:when test=
"$thesaurus_code1 = 'c'"><xslo:text>mesh
</xslo:text></xslo:when>
160 <xslo:when test=
"$thesaurus_code1 = 'd'"><xslo:text>nal
</xslo:text></xslo:when>
161 <xslo:when test=
"$thesaurus_code1 = 'k'"><xslo:text>cash
</xslo:text></xslo:when>
162 <xslo:when test=
"$thesaurus_code1 = 'n'"><xslo:text>notapplicable
</xslo:text></xslo:when>
163 <xslo:when test=
"$thesaurus_code1 = 'r'"><xslo:text>aat
</xslo:text></xslo:when>
164 <xslo:when test=
"$thesaurus_code1 = 's'"><xslo:text>sears
</xslo:text></xslo:when>
165 <xslo:when test=
"$thesaurus_code1 = 'v'"><xslo:text>rvm
</xslo:text></xslo:when>
166 <xslo:when test=
"$thesaurus_code1 = 'z'">
169 <xsl:attribute name=
"test"><xsl:value-of select=
"$alt_select"/></xsl:attribute>
171 <xsl:attribute name=
"select"><xsl:value-of select=
"$alt_select"/></xsl:attribute>
174 <xslo:otherwise><xslo:text>notdefined
</xslo:text></xslo:otherwise>
177 <xslo:otherwise><xslo:text>notdefined
</xslo:text></xslo:otherwise>
181 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
182 <xslo:value-of select=
"$full_thesaurus_code"/>
187 <xsl:template name=
"handle-index-leader">
188 <xsl:if test=
"kohaidx:index_leader">
189 <xslo:template match=
"marc:leader">
190 <xsl:apply-templates select=
"kohaidx:index_leader" mode=
"secondary"/>
195 <xsl:template match=
"kohaidx:index_leader" mode=
"secondary">
196 <xsl:variable name=
"offset"><xsl:value-of select=
"@offset"/></xsl:variable>
197 <xsl:variable name=
"length"><xsl:value-of select=
"@length"/></xsl:variable>
198 <xsl:variable name=
"indexes">
199 <xsl:call-template name=
"get-target-indexes"/>
202 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
204 <xsl:attribute name=
"select">
205 <xsl:text>substring(.,
</xsl:text>
206 <xsl:value-of select=
"$offset + 1" />
207 <xsl:text>,
</xsl:text>
208 <xsl:value-of select=
"$length" />
209 <xsl:text>)
</xsl:text>
215 <xsl:template name=
"handle-index-control-field">
216 <xsl:for-each select=
"//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
218 <xsl:attribute name=
"match">
219 <xsl:text>marc:controlfield[@tag='
</xsl:text>
220 <xsl:value-of select=
"@tag"/>
221 <xsl:text>']
</xsl:text>
223 <xsl:for-each select=
"key('index_control_field_tag', @tag)">
224 <xsl:call-template name=
"handle-one-index-control-field"/>
230 <xsl:template name=
"handle-one-index-control-field">
231 <xsl:variable name=
"offset"><xsl:value-of select=
"@offset"/></xsl:variable>
232 <xsl:variable name=
"length"><xsl:value-of select=
"@length"/></xsl:variable>
233 <xsl:variable name=
"indexes">
234 <xsl:call-template name=
"get-target-indexes"/>
237 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
239 <xsl:attribute name=
"select">
241 <xsl:when test=
"@length">
242 <xsl:text>substring(.,
</xsl:text>
243 <xsl:value-of select=
"$offset + 1" />
244 <xsl:text>,
</xsl:text>
245 <xsl:value-of select=
"$length"/>
246 <xsl:text>)
</xsl:text>
249 <xsl:text>.
</xsl:text>
257 <xsl:template name=
"handle-index-subfields">
258 <xsl:for-each select=
"//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
259 <xslo:template mode=
"index_subfields">
260 <xsl:attribute name=
"match">
261 <xsl:text>marc:datafield[@tag='
</xsl:text>
262 <xsl:value-of select=
"@tag"/>
263 <xsl:text>']
</xsl:text>
265 <xsl:for-each select=
"key('index_subfields_tag', @tag)">
267 <xsl:when test=
"@condition">
269 <xsl:attribute name=
"test">
270 <xsl:value-of select=
"@condition"/>
272 <xsl:call-template name=
"handle-one-index-subfields" />
276 <xsl:call-template name=
"handle-one-index-subfields" />
284 <xsl:template name=
"handle-one-index-subfields">
285 <xsl:variable name=
"offset"><xsl:value-of select=
"@offset"/></xsl:variable>
286 <xsl:variable name=
"length"><xsl:value-of select=
"@length"/></xsl:variable>
287 <xsl:variable name=
"indexes">
288 <xsl:call-template name=
"get-target-indexes"/>
291 <xslo:for-each select=
"marc:subfield">
293 <xsl:attribute name=
"test">
294 <xsl:text>contains('
</xsl:text>
295 <xsl:value-of select=
"@subfields"/>
296 <xsl:text>', @code)
</xsl:text>
299 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
301 <xsl:attribute name=
"select">
303 <xsl:when test=
"@length">
304 <xsl:text>substring(.,
</xsl:text>
305 <xsl:value-of select=
"$offset + 1" />
306 <xsl:text>,
</xsl:text>
307 <xsl:value-of select=
"$length"/>
308 <xsl:text>)
</xsl:text>
311 <xsl:text>.
</xsl:text>
321 <xsl:template name=
"handle-index-facets">
322 <xsl:for-each select=
"//kohaidx:facet[generate-id() = generate-id(key('index_facet_tag', @tag)[1])]">
323 <xslo:template mode=
"index_facets">
324 <xsl:attribute name=
"match">
325 <xsl:text>marc:datafield[@tag='
</xsl:text>
326 <xsl:value-of select=
"@tag"/>
327 <xsl:text>']
</xsl:text>
330 <xsl:attribute name=
"test">
331 <xsl:text>not(@ind1='z')
</xsl:text>
333 <xsl:for-each select=
"key('index_facet_tag', @tag)">
334 <xsl:variable name=
"indexes">
335 <xsl:call-template name=
"get-facets-target-indexes"/>
337 <xsl:if test=
"not($indexes='')">
339 <xsl:attribute name=
"name">
340 <xsl:value-of select=
"normalize-space($indexes)"/>
342 <xsl:call-template name=
"build-facet-value">
343 <xsl:with-param name=
"subfields" select=
"@subfields"/>
353 <xsl:template name=
"handle-index-data-field">
354 <xsl:for-each select=
"//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
355 <xslo:template mode=
"index_data_field">
356 <xsl:attribute name=
"match">
357 <xsl:text>marc:datafield[@tag='
</xsl:text>
358 <xsl:value-of select=
"@tag"/>
359 <xsl:text>']
</xsl:text>
361 <xsl:for-each select=
"key('index_data_field_tag', @tag)">
362 <xsl:call-template name=
"handle-one-data-field"/>
368 <xsl:template name=
"handle-index-heading-conditional">
369 <xsl:for-each select=
"//kohaidx:index_heading_conditional[generate-id() = generate-id(key('index_heading_conditional_tag', @tag)[1])]">
370 <xslo:template mode=
"index_heading_conditional">
371 <xsl:attribute name=
"match">marc:datafield[@tag='
<xsl:value-of select=
"@tag"/>']
</xsl:attribute>
373 <xsl:attribute name=
"test"><xsl:value-of select=
"@test"/></xsl:attribute>
374 <xsl:for-each select=
"key('index_heading_conditional_tag', @tag)">
375 <xsl:call-template name=
"handle-one-index-heading"/>
382 <xsl:template name=
"handle-one-data-field">
383 <xsl:variable name=
"indexes">
384 <xsl:call-template name=
"get-target-indexes"/>
387 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
388 <xslo:variable name=
"raw_heading">
389 <xslo:for-each select=
"marc:subfield">
390 <xslo:if test=
"position() > 1">
391 <xslo:value-of select=
"substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
393 <xslo:value-of select=
"."/>
396 <xslo:value-of select=
"normalize-space($raw_heading)"/>
400 <xsl:template name=
"handle-index-heading">
401 <xsl:for-each select=
"//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
402 <xslo:template mode=
"index_heading">
403 <xsl:attribute name=
"match">
404 <xsl:text>marc:datafield[@tag='
</xsl:text>
405 <xsl:value-of select=
"@tag"/>
406 <xsl:text>']
</xsl:text>
408 <xsl:for-each select=
"key('index_heading_tag', @tag)">
409 <xsl:call-template name=
"handle-one-index-heading"/>
415 <xsl:template name=
"handle-one-index-heading">
416 <xsl:variable name=
"indexes">
417 <xsl:call-template name=
"get-target-indexes"/>
420 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
421 <xslo:variable name=
"raw_heading">
422 <xslo:for-each select=
"marc:subfield">
424 <xsl:attribute name=
"test">
425 <xsl:text>contains('
</xsl:text>
426 <xsl:value-of select=
"@subfields"/>
427 <xsl:text>', @code)
</xsl:text>
429 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
430 <xslo:if test=
"position() > 1">
433 <xsl:attribute name=
"test">
434 <xsl:text>contains('
</xsl:text>
435 <xsl:value-of select=
"@subdivisions"/>
436 <xsl:text>', @code)
</xsl:text>
438 <xslo:text>--
</xslo:text>
441 <xslo:value-of select=
"substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
445 <xslo:value-of select=
"."/>
449 <xslo:value-of select=
"normalize-space($raw_heading)"/>
453 <xsl:template name=
"handle-index-match-heading">
454 <xsl:for-each select=
"//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
455 <xslo:template mode=
"index_match_heading">
456 <xsl:attribute name=
"match">
457 <xsl:text>marc:datafield[@tag='
</xsl:text>
458 <xsl:value-of select=
"@tag"/>
459 <xsl:text>']
</xsl:text>
461 <xsl:for-each select=
"key('index_match_heading_tag', @tag)">
462 <xsl:call-template name=
"handle-one-index-match-heading"/>
468 <xsl:template name=
"handle-one-index-match-heading">
469 <xsl:variable name=
"indexes">
470 <xsl:call-template name=
"get-target-indexes"/>
473 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
474 <xslo:variable name=
"raw_heading">
475 <xslo:for-each select=
"marc:subfield">
477 <xsl:attribute name=
"test">
478 <xsl:text>contains('
</xsl:text>
479 <xsl:value-of select=
"@subfields"/>
480 <xsl:text>', @code)
</xsl:text>
482 <xsl:attribute name=
"name"><xsl:value-of select=
"normalize-space($indexes)"/></xsl:attribute>
483 <xslo:if test=
"position() > 1">
486 <xsl:attribute name=
"test">
487 <xsl:text>contains('
</xsl:text>
488 <xsl:value-of select=
"@subdivisions"/>
489 <xsl:text>', @code)
</xsl:text>
493 <xsl:attribute name=
"test">
494 <xsl:text>@code = $general_subdivision_subfield
</xsl:text>
496 <xslo:text> generalsubdiv
</xslo:text>
499 <xsl:attribute name=
"test">
500 <xsl:text>@code = $form_subdivision_subfield
</xsl:text>
502 <xslo:text> formsubdiv
</xslo:text>
505 <xsl:attribute name=
"test">
506 <xsl:text>@code = $chronological_subdivision_subfield
</xsl:text>
508 <xslo:text> chronologicalsubdiv
</xslo:text>
511 <xsl:attribute name=
"test">
512 <xsl:text>@code = $geographic_subdivision_subfield
</xsl:text>
514 <xslo:text> geographicsubdiv
</xslo:text>
519 <xslo:value-of select=
"substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
523 <xslo:call-template name=
"chopPunctuation">
524 <xslo:with-param name=
"chopString">
525 <xslo:value-of select=
"."/>
527 </xslo:call-template>
531 <xslo:value-of select=
"normalize-space($raw_heading)"/>
535 <xsl:template name=
"get-target-indexes">
536 <xsl:for-each select=
"kohaidx:target_index">
537 <xsl:value-of select=
"." /><xsl:text> </xsl:text>
541 <xsl:template name=
"get-facets-target-indexes">
542 <xsl:for-each select=
"kohaidx:target_index">
543 <xsl:value-of select=
"." /><xsl:text> </xsl:text>
547 <!-- traverse subfields string character-wise -->
548 <xsl:template name=
"build-facet-value">
549 <xsl:param name=
"subfields"/>
550 <xsl:if test=
"string-length($subfields) > 0">
552 <xsl:attribute name=
"select">
553 <xsl:text>marc:subfield[@code='
</xsl:text>
554 <xsl:value-of select=
"substring($subfields,1,1)"/>
555 <xsl:text>']
</xsl:text>
558 <xsl:call-template name=
"build-facet-value-cont">
559 <xsl:with-param name=
"prev" select=
"substring($subfields,1,1)"/>
560 <xsl:with-param name=
"subfields" select=
"substring($subfields,2)"/>
564 <!-- traverse the remainder of @subfields, with context information
565 i.e previous char. Introduces a separator character if needed -->
566 <xsl:template name=
"build-facet-value-cont">
567 <xsl:param name=
"prev"/>
568 <xsl:param name=
"subfields"/>
569 <xsl:if test=
"string-length($subfields) > 0">
571 <xsl:attribute name=
"test">
572 <xsl:text>marc:subfield[@code='
</xsl:text>
573 <xsl:value-of select=
"$prev"/>
574 <xsl:text>'] and marc:subfield[@code='
</xsl:text>
575 <xsl:value-of select=
"substring($subfields,1,1)"/>
576 <xsl:text>']
</xsl:text>
578 <xslo:text><*
></xslo:text>
581 <xsl:attribute name=
"select">
582 <xsl:text>marc:subfield[@code='
</xsl:text>
583 <xsl:value-of select=
"substring($subfields,1,1)"/>
584 <xsl:text>']
</xsl:text>
587 <xsl:call-template name=
"build-facet-value-cont">
588 <xsl:with-param name=
"prev" select=
"substring($subfields,1,1)"/>
589 <xsl:with-param name=
"subfields" select=
"substring($subfields,2)"/>