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="/">
43 <xslo:if test="marc:collection">
45 <xslo:apply-templates select="marc:collection/marc:record"/>
48 <xslo:if test="marc:record">
49 <xslo:apply-templates select="marc:record"/>
53 <xslo:template match="marc:record">
54 <xslo:variable name="idfield">
55 <xsl:attribute name="select">normalize-space(<xsl:value-of select="//kohaidx:id"/>)</xsl:attribute>
57 <z:record type="update">
58 <xslo:attribute name="z:id"><xslo:value-of select="$idfield"/></xslo:attribute>
59 <xslo:apply-templates/>
60 <xslo:apply-templates mode="index_subfields"/>
61 <xslo:apply-templates mode="index_data_field"/>
62 <xslo:apply-templates mode="index_facets"/>
63 <xslo:apply-templates mode="index_heading"/>
64 <xslo:apply-templates mode="index_heading_conditional"/>
65 <xslo:apply-templates mode="index_match_heading"/>
66 <xslo:apply-templates mode="index_subject_thesaurus"/>
67 <xslo:apply-templates mode="index_all"/>
71 <xsl:call-template name="handle-index-leader"/>
72 <xsl:call-template name="handle-index-control-field"/>
73 <xsl:call-template name="handle-index-subfields"/>
74 <xsl:call-template name="handle-index-data-field"/>
75 <xsl:call-template name="handle-index-facets"/>
76 <xsl:call-template name="handle-index-heading"/>
77 <xsl:call-template name="handle-index-heading-conditional"/>
78 <xsl:call-template name="handle-index-match-heading"/>
79 <xsl:apply-templates/>
80 <xslo:template mode="index_all" match="text()">
81 <z:index name="Any:w Any:p">
82 <xslo:value-of select="."/>
85 <xslo:template name="chopPunctuation">
86 <xslo:param name="chopString"/>
87 <xslo:variable name="length" select="string-length($chopString)"/>
89 <xslo:when test="$length=0"/>
90 <xslo:when test="contains('-,.:=;!%/', substring($chopString,$length,1))">
91 <xslo:call-template name="chopPunctuation">
92 <xslo:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
95 <xslo:when test="not($chopString)"/>
96 <xslo:otherwise><xslo:value-of select="$chopString"/></xslo:otherwise>
98 <xslo:text> </xslo:text>
103 <!-- map kohaidx:var to stylesheet variables -->
104 <xsl:template match="kohaidx:var">
106 <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
107 <xsl:value-of select="."/>
111 <xsl:template match="kohaidx:index_subject_thesaurus">
112 <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
113 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
114 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
115 <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
116 <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
117 <xsl:variable name="indexes">
118 <xsl:call-template name="get-target-indexes"/>
120 <xslo:template mode="index_subject_thesaurus">
121 <xsl:attribute name="match">
122 <xsl:text>marc:controlfield[@tag='</xsl:text>
123 <xsl:value-of select="$tag"/>
124 <xsl:text>']</xsl:text>
126 <xslo:variable name="thesaurus_code1">
127 <xsl:attribute name="select">
128 <xsl:text>substring(., </xsl:text>
129 <xsl:value-of select="$offset + 1" />
130 <xsl:text>, </xsl:text>
131 <xsl:value-of select="$length" />
132 <xsl:text>)</xsl:text>
135 <xsl:variable name="alt_select">
136 <xsl:text>//marc:datafield[@tag='</xsl:text>
137 <xsl:value-of select="$detail_tag"/>
138 <xsl:text>']/marc:subfield[@code='</xsl:text>
139 <xsl:value-of select="$detail_subfields"/>
140 <xsl:text>']</xsl:text>
142 <xslo:variable name="full_thesaurus_code">
144 <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
145 <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
146 <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
147 <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
148 <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
149 <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
150 <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
151 <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
152 <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
153 <xslo:when test="$thesaurus_code1 = 'z'">
156 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
158 <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
161 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
164 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
168 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
169 <xslo:value-of select="$full_thesaurus_code"/>
174 <xsl:template name="handle-index-leader">
175 <xsl:if test="kohaidx:index_leader">
176 <xslo:template match="marc:leader">
177 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
182 <xsl:template match="kohaidx:index_leader" mode="secondary">
183 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
184 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
185 <xsl:variable name="indexes">
186 <xsl:call-template name="get-target-indexes"/>
189 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
191 <xsl:attribute name="select">
192 <xsl:text>substring(., </xsl:text>
193 <xsl:value-of select="$offset + 1" />
194 <xsl:text>, </xsl:text>
195 <xsl:value-of select="$length" />
196 <xsl:text>)</xsl:text>
202 <xsl:template name="handle-index-control-field">
203 <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
205 <xsl:attribute name="match">
206 <xsl:text>marc:controlfield[@tag='</xsl:text>
207 <xsl:value-of select="@tag"/>
208 <xsl:text>']</xsl:text>
210 <xsl:for-each select="key('index_control_field_tag', @tag)">
211 <xsl:call-template name="handle-one-index-control-field"/>
217 <xsl:template name="handle-one-index-control-field">
218 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
219 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
220 <xsl:variable name="indexes">
221 <xsl:call-template name="get-target-indexes"/>
224 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
226 <xsl:attribute name="select">
228 <xsl:when test="@length">
229 <xsl:text>substring(., </xsl:text>
230 <xsl:value-of select="$offset + 1" />
231 <xsl:text>, </xsl:text>
232 <xsl:value-of select="$length"/>
233 <xsl:text>)</xsl:text>
236 <xsl:text>.</xsl:text>
244 <xsl:template name="handle-index-subfields">
245 <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
246 <xslo:template mode="index_subfields">
247 <xsl:attribute name="match">
248 <xsl:text>marc:datafield[@tag='</xsl:text>
249 <xsl:value-of select="@tag"/>
250 <xsl:text>']</xsl:text>
252 <xsl:for-each select="key('index_subfields_tag', @tag)">
254 <xsl:when test="@condition">
256 <xsl:attribute name="test">
257 <xsl:value-of select="@condition"/>
259 <xsl:call-template name="handle-one-index-subfields" />
263 <xsl:call-template name="handle-one-index-subfields" />
271 <xsl:template name="handle-one-index-subfields">
272 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
273 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
274 <xsl:variable name="indexes">
275 <xsl:call-template name="get-target-indexes"/>
278 <xslo:for-each select="marc:subfield">
280 <xsl:attribute name="test">
281 <xsl:text>contains('</xsl:text>
282 <xsl:value-of select="@subfields"/>
283 <xsl:text>', @code)</xsl:text>
286 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
288 <xsl:attribute name="select">
290 <xsl:when test="@length">
291 <xsl:text>substring(., </xsl:text>
292 <xsl:value-of select="$offset + 1" />
293 <xsl:text>, </xsl:text>
294 <xsl:value-of select="$length"/>
295 <xsl:text>)</xsl:text>
298 <xsl:text>.</xsl:text>
308 <xsl:template name="handle-index-facets">
309 <xsl:for-each select="//kohaidx:facet[generate-id() = generate-id(key('index_facet_tag', @tag)[1])]">
310 <xslo:template mode="index_facets">
311 <xsl:attribute name="match">
312 <xsl:text>marc:datafield[@tag='</xsl:text>
313 <xsl:value-of select="@tag"/>
314 <xsl:text>']</xsl:text>
317 <xsl:attribute name="test">
318 <xsl:text>not(@ind1='z')</xsl:text>
320 <xsl:for-each select="key('index_facet_tag', @tag)">
321 <xsl:variable name="indexes">
322 <xsl:call-template name="get-facets-target-indexes"/>
324 <xsl:if test="not($indexes='')">
326 <xsl:attribute name="name">
327 <xsl:value-of select="normalize-space($indexes)"/>
329 <xsl:call-template name="build-facet-value">
330 <xsl:with-param name="subfields" select="@subfields"/>
340 <xsl:template name="handle-index-data-field">
341 <xsl:for-each select="//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
342 <xslo:template mode="index_data_field">
343 <xsl:attribute name="match">
344 <xsl:text>marc:datafield[@tag='</xsl:text>
345 <xsl:value-of select="@tag"/>
346 <xsl:text>']</xsl:text>
348 <xsl:for-each select="key('index_data_field_tag', @tag)">
349 <xsl:call-template name="handle-one-data-field"/>
355 <xsl:template name="handle-index-heading-conditional">
356 <xsl:for-each select="//kohaidx:index_heading_conditional[generate-id() = generate-id(key('index_heading_conditional_tag', @tag)[1])]">
357 <xslo:template mode="index_heading_conditional">
358 <xsl:attribute name="match">marc:datafield[@tag='<xsl:value-of select="@tag"/>']</xsl:attribute>
360 <xsl:attribute name="test"><xsl:value-of select="@test"/></xsl:attribute>
361 <xsl:for-each select="key('index_heading_conditional_tag', @tag)">
362 <xsl:call-template name="handle-one-index-heading"/>
369 <xsl:template name="handle-one-data-field">
370 <xsl:variable name="indexes">
371 <xsl:call-template name="get-target-indexes"/>
374 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
375 <xslo:variable name="raw_heading">
376 <xslo:for-each select="marc:subfield">
377 <xslo:if test="position() > 1">
378 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
380 <xslo:value-of select="."/>
383 <xslo:value-of select="normalize-space($raw_heading)"/>
387 <xsl:template name="handle-index-heading">
388 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
389 <xslo:template mode="index_heading">
390 <xsl:attribute name="match">
391 <xsl:text>marc:datafield[@tag='</xsl:text>
392 <xsl:value-of select="@tag"/>
393 <xsl:text>']</xsl:text>
395 <xsl:for-each select="key('index_heading_tag', @tag)">
396 <xsl:call-template name="handle-one-index-heading"/>
402 <xsl:template name="handle-one-index-heading">
403 <xsl:variable name="indexes">
404 <xsl:call-template name="get-target-indexes"/>
407 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
408 <xslo:variable name="raw_heading">
409 <xslo:for-each select="marc:subfield">
411 <xsl:attribute name="test">
412 <xsl:text>contains('</xsl:text>
413 <xsl:value-of select="@subfields"/>
414 <xsl:text>', @code)</xsl:text>
416 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
417 <xslo:if test="position() > 1">
420 <xsl:attribute name="test">
421 <xsl:text>contains('</xsl:text>
422 <xsl:value-of select="@subdivisions"/>
423 <xsl:text>', @code)</xsl:text>
425 <xslo:text>--</xslo:text>
428 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
432 <xslo:value-of select="."/>
436 <xslo:value-of select="normalize-space($raw_heading)"/>
440 <xsl:template name="handle-index-match-heading">
441 <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
442 <xslo:template mode="index_match_heading">
443 <xsl:attribute name="match">
444 <xsl:text>marc:datafield[@tag='</xsl:text>
445 <xsl:value-of select="@tag"/>
446 <xsl:text>']</xsl:text>
448 <xsl:for-each select="key('index_match_heading_tag', @tag)">
449 <xsl:call-template name="handle-one-index-match-heading"/>
455 <xsl:template name="handle-one-index-match-heading">
456 <xsl:variable name="indexes">
457 <xsl:call-template name="get-target-indexes"/>
460 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
461 <xslo:variable name="raw_heading">
462 <xslo:for-each select="marc:subfield">
464 <xsl:attribute name="test">
465 <xsl:text>contains('</xsl:text>
466 <xsl:value-of select="@subfields"/>
467 <xsl:text>', @code)</xsl:text>
469 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
470 <xslo:if test="position() > 1">
473 <xsl:attribute name="test">
474 <xsl:text>contains('</xsl:text>
475 <xsl:value-of select="@subdivisions"/>
476 <xsl:text>', @code)</xsl:text>
480 <xsl:attribute name="test">
481 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
483 <xslo:text> generalsubdiv </xslo:text>
486 <xsl:attribute name="test">
487 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
489 <xslo:text> formsubdiv </xslo:text>
492 <xsl:attribute name="test">
493 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
495 <xslo:text> chronologicalsubdiv </xslo:text>
498 <xsl:attribute name="test">
499 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
501 <xslo:text> geographicsubdiv </xslo:text>
506 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
510 <xslo:call-template name="chopPunctuation">
511 <xslo:with-param name="chopString">
512 <xslo:value-of select="."/>
514 </xslo:call-template>
518 <xslo:value-of select="normalize-space($raw_heading)"/>
522 <xsl:template name="get-target-indexes">
523 <xsl:for-each select="kohaidx:target_index">
524 <xsl:value-of select="." /><xsl:text> </xsl:text>
528 <xsl:template name="get-facets-target-indexes">
529 <xsl:for-each select="kohaidx:target_index">
530 <xsl:value-of select="." /><xsl:text> </xsl:text>
534 <!-- traverse subfields string character-wise -->
535 <xsl:template name="build-facet-value">
536 <xsl:param name="subfields"/>
537 <xsl:if test="string-length($subfields) > 0">
539 <xsl:attribute name="select">
540 <xsl:text>marc:subfield[@code='</xsl:text>
541 <xsl:value-of select="substring($subfields,1,1)"/>
542 <xsl:text>']</xsl:text>
545 <xsl:call-template name="build-facet-value-cont">
546 <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
547 <xsl:with-param name="subfields" select="substring($subfields,2)"/>
551 <!-- traverse the remainder of @subfields, with context information
552 i.e previous char. Introduces a separator character if needed -->
553 <xsl:template name="build-facet-value-cont">
554 <xsl:param name="prev"/>
555 <xsl:param name="subfields"/>
556 <xsl:if test="string-length($subfields) > 0">
558 <xsl:attribute name="test">
559 <xsl:text>marc:subfield[@code='</xsl:text>
560 <xsl:value-of select="$prev"/>
561 <xsl:text>'] and marc:subfield[@code='</xsl:text>
562 <xsl:value-of select="substring($subfields,1,1)"/>
563 <xsl:text>']</xsl:text>
565 <xslo:text><*></xslo:text>
568 <xsl:attribute name="select">
569 <xsl:text>marc:subfield[@code='</xsl:text>
570 <xsl:value-of select="substring($subfields,1,1)"/>
571 <xsl:text>']</xsl:text>
574 <xsl:call-template name="build-facet-value-cont">
575 <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
576 <xsl:with-param name="subfields" select="substring($subfields,2)"/>