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="//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)">
253 <xsl:call-template name="handle-one-index-subfields"/>
259 <xsl:template name="handle-one-index-subfields">
260 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
261 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
262 <xsl:variable name="indexes">
263 <xsl:call-template name="get-target-indexes"/>
265 <xslo:for-each select="marc:subfield">
267 <xsl:attribute name="test">
268 <xsl:text>contains('</xsl:text>
269 <xsl:value-of select="@subfields"/>
270 <xsl:text>', @code)</xsl:text>
273 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
275 <xsl:attribute name="select">
277 <xsl:when test="@length">
278 <xsl:text>substring(., </xsl:text>
279 <xsl:value-of select="$offset + 1" />
280 <xsl:text>, </xsl:text>
281 <xsl:value-of select="$length"/>
282 <xsl:text>)</xsl:text>
285 <xsl:text>.</xsl:text>
295 <xsl:template name="handle-index-facets">
296 <xsl:for-each select="//kohaidx:facet[generate-id() = generate-id(key('index_facet_tag', @tag)[1])]">
297 <xslo:template mode="index_facets">
298 <xsl:attribute name="match">
299 <xsl:text>marc:datafield[@tag='</xsl:text>
300 <xsl:value-of select="@tag"/>
301 <xsl:text>']</xsl:text>
304 <xsl:attribute name="test">
305 <xsl:text>not(@ind1='z')</xsl:text>
307 <xsl:for-each select="key('index_facet_tag', @tag)">
308 <xsl:variable name="indexes">
309 <xsl:call-template name="get-facets-target-indexes"/>
311 <xsl:if test="not($indexes='')">
313 <xsl:attribute name="name">
314 <xsl:value-of select="normalize-space($indexes)"/>
316 <xsl:call-template name="build-facet-value">
317 <xsl:with-param name="subfields" select="@subfields"/>
327 <xsl:template name="handle-index-data-field">
328 <xsl:for-each select="//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
329 <xslo:template mode="index_data_field">
330 <xsl:attribute name="match">
331 <xsl:text>marc:datafield[@tag='</xsl:text>
332 <xsl:value-of select="@tag"/>
333 <xsl:text>']</xsl:text>
335 <xsl:for-each select="key('index_data_field_tag', @tag)">
336 <xsl:call-template name="handle-one-data-field"/>
342 <xsl:template name="handle-index-heading-conditional">
343 <xsl:for-each select="//kohaidx:index_heading_conditional[generate-id() = generate-id(key('index_heading_conditional_tag', @tag)[1])]">
344 <xslo:template mode="index_heading_conditional">
345 <xsl:attribute name="match">marc:datafield[@tag='<xsl:value-of select="@tag"/>']</xsl:attribute>
347 <xsl:attribute name="test"><xsl:value-of select="@test"/></xsl:attribute>
348 <xsl:for-each select="key('index_heading_conditional_tag', @tag)">
349 <xsl:call-template name="handle-one-index-heading"/>
356 <xsl:template name="handle-one-data-field">
357 <xsl:variable name="indexes">
358 <xsl:call-template name="get-target-indexes"/>
361 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
362 <xslo:variable name="raw_heading">
363 <xslo:for-each select="marc:subfield">
364 <xslo:if test="position() > 1">
365 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
367 <xslo:value-of select="."/>
370 <xslo:value-of select="normalize-space($raw_heading)"/>
374 <xsl:template name="handle-index-heading">
375 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
376 <xslo:template mode="index_heading">
377 <xsl:attribute name="match">
378 <xsl:text>marc:datafield[@tag='</xsl:text>
379 <xsl:value-of select="@tag"/>
380 <xsl:text>']</xsl:text>
382 <xsl:for-each select="key('index_heading_tag', @tag)">
383 <xsl:call-template name="handle-one-index-heading"/>
389 <xsl:template name="handle-one-index-heading">
390 <xsl:variable name="indexes">
391 <xsl:call-template name="get-target-indexes"/>
394 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
395 <xslo:variable name="raw_heading">
396 <xslo:for-each select="marc:subfield">
398 <xsl:attribute name="test">
399 <xsl:text>contains('</xsl:text>
400 <xsl:value-of select="@subfields"/>
401 <xsl:text>', @code)</xsl:text>
403 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
404 <xslo:if test="position() > 1">
407 <xsl:attribute name="test">
408 <xsl:text>contains('</xsl:text>
409 <xsl:value-of select="@subdivisions"/>
410 <xsl:text>', @code)</xsl:text>
412 <xslo:text>--</xslo:text>
415 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
419 <xslo:value-of select="."/>
423 <xslo:value-of select="normalize-space($raw_heading)"/>
427 <xsl:template name="handle-index-match-heading">
428 <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
429 <xslo:template mode="index_match_heading">
430 <xsl:attribute name="match">
431 <xsl:text>marc:datafield[@tag='</xsl:text>
432 <xsl:value-of select="@tag"/>
433 <xsl:text>']</xsl:text>
435 <xsl:for-each select="key('index_match_heading_tag', @tag)">
436 <xsl:call-template name="handle-one-index-match-heading"/>
442 <xsl:template name="handle-one-index-match-heading">
443 <xsl:variable name="indexes">
444 <xsl:call-template name="get-target-indexes"/>
447 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
448 <xslo:variable name="raw_heading">
449 <xslo:for-each select="marc:subfield">
451 <xsl:attribute name="test">
452 <xsl:text>contains('</xsl:text>
453 <xsl:value-of select="@subfields"/>
454 <xsl:text>', @code)</xsl:text>
456 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
457 <xslo:if test="position() > 1">
460 <xsl:attribute name="test">
461 <xsl:text>contains('</xsl:text>
462 <xsl:value-of select="@subdivisions"/>
463 <xsl:text>', @code)</xsl:text>
467 <xsl:attribute name="test">
468 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
470 <xslo:text> generalsubdiv </xslo:text>
473 <xsl:attribute name="test">
474 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
476 <xslo:text> formsubdiv </xslo:text>
479 <xsl:attribute name="test">
480 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
482 <xslo:text> chronologicalsubdiv </xslo:text>
485 <xsl:attribute name="test">
486 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
488 <xslo:text> geographicsubdiv </xslo:text>
493 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
497 <xslo:call-template name="chopPunctuation">
498 <xslo:with-param name="chopString">
499 <xslo:value-of select="."/>
501 </xslo:call-template>
505 <xslo:value-of select="normalize-space($raw_heading)"/>
509 <xsl:template name="get-target-indexes">
510 <xsl:for-each select="kohaidx:target_index">
511 <xsl:value-of select="." /><xsl:text> </xsl:text>
515 <xsl:template name="get-facets-target-indexes">
516 <xsl:for-each select="kohaidx:target_index">
517 <xsl:value-of select="." /><xsl:text> </xsl:text>
521 <!-- traverse subfields string character-wise -->
522 <xsl:template name="build-facet-value">
523 <xsl:param name="subfields"/>
524 <xsl:if test="string-length($subfields) > 0">
526 <xsl:attribute name="select">
527 <xsl:text>marc:subfield[@code='</xsl:text>
528 <xsl:value-of select="substring($subfields,1,1)"/>
529 <xsl:text>']</xsl:text>
532 <xsl:call-template name="build-facet-value-cont">
533 <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
534 <xsl:with-param name="subfields" select="substring($subfields,2)"/>
538 <!-- traverse the remainder of @subfields, with context information
539 i.e previous char. Introduces a separator character if needed -->
540 <xsl:template name="build-facet-value-cont">
541 <xsl:param name="prev"/>
542 <xsl:param name="subfields"/>
543 <xsl:if test="string-length($subfields) > 0">
545 <xsl:attribute name="test">
546 <xsl:text>marc:subfield[@code='</xsl:text>
547 <xsl:value-of select="$prev"/>
548 <xsl:text>'] and marc:subfield[@code='</xsl:text>
549 <xsl:value-of select="substring($subfields,1,1)"/>
550 <xsl:text>']</xsl:text>
552 <xslo:text><*></xslo:text>
555 <xsl:attribute name="select">
556 <xsl:text>marc:subfield[@code='</xsl:text>
557 <xsl:value-of select="substring($subfields,1,1)"/>
558 <xsl:text>']</xsl:text>
561 <xsl:call-template name="build-facet-value-cont">
562 <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
563 <xsl:with-param name="subfields" select="substring($subfields,2)"/>