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_heading_tag" match="kohaidx:index_heading" use="@tag"/>
18 <xsl:key name="index_data_field_tag" match="kohaidx:index_data_field" use="@tag"/>
19 <xsl:key name="index_match_heading_tag" match="kohaidx:index_match_heading" use="@tag"/>
21 <xsl:template match="kohaidx:index_defs">
23 This file has been automatically generated from a Koha index definition file
24 with the stylesheet koha-indexdefs-to-zebra.xsl. Do not manually edit this file,
25 as it may be overwritten. To regenerate, edit the appropriate Koha index
26 definition file (probably something like {biblio,authority}-koha-indexdefs.xml) and run:
27 `xsltproc koha-indexdefs-to-zebra.xsl {biblio,authority}-koha-indexdefs.xml >
28 {biblio,authority}-zebra-indexdefs.xsl` (substituting the appropriate file names).
30 <xslo:stylesheet version="1.0">
31 <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
32 <xslo:template match="text()"/>
33 <xslo:template match="text()" mode="index_subfields"/>
34 <xslo:template match="text()" mode="index_data_field"/>
35 <xslo:template match="text()" mode="index_heading"/>
36 <xslo:template match="text()" mode="index_match_heading"/>
37 <xslo:template match="text()" mode="index_subject_thesaurus"/>
38 <xslo:template match="/">
39 <xslo:if test="marc:collection">
41 <xslo:apply-templates select="marc:collection/marc:record"/>
44 <xslo:if test="marc:record">
45 <xslo:apply-templates select="marc:record"/>
49 <xslo:template match="marc:record">
50 <xslo:variable name="controlField001" select="normalize-space(marc:controlfield[@tag='001'])"/>
51 <z:record type="update">
52 <xslo:attribute name="z:id"><xslo:value-of select="$controlField001"/></xslo:attribute>
53 <xslo:apply-templates/>
54 <xslo:apply-templates mode="index_subfields"/>
55 <xslo:apply-templates mode="index_data_field"/>
56 <xslo:apply-templates mode="index_heading"/>
57 <xslo:apply-templates mode="index_match_heading"/>
58 <xslo:apply-templates mode="index_subject_thesaurus"/>
62 <xsl:call-template name="handle-index-leader"/>
63 <xsl:call-template name="handle-index-control-field"/>
64 <xsl:call-template name="handle-index-subfields"/>
65 <xsl:call-template name="handle-index-data-field"/>
66 <xsl:call-template name="handle-index-heading"/>
67 <xsl:call-template name="handle-index-match-heading"/>
68 <xsl:apply-templates/>
69 <xslo:template match="*">
70 <z:index name="Any:w Any:p">
71 <xslo:value-of select="."/>
74 <xslo:template name="chopPunctuation">
75 <xslo:param name="chopString"/>
76 <xslo:variable name="length" select="string-length($chopString)"/>
78 <xslo:when test="$length=0"/>
79 <xslo:when test="contains('-,.:=;!%/', substring($chopString,$length,1))">
80 <xslo:call-template name="chopPunctuation">
81 <xslo:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
84 <xslo:when test="not($chopString)"/>
85 <xslo:otherwise><xslo:value-of select="$chopString"/></xslo:otherwise>
87 <xslo:text> </xslo:text>
92 <!-- map kohaidx:var to stylesheet variables -->
93 <xsl:template match="kohaidx:var">
95 <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
96 <xsl:value-of select="."/>
100 <xsl:template match="kohaidx:index_subject_thesaurus">
101 <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
102 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
103 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
104 <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
105 <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
106 <xsl:variable name="indexes">
107 <xsl:call-template name="get-target-indexes"/>
109 <xslo:template mode="index_subject_thesaurus">
110 <xsl:attribute name="match">
111 <xsl:text>marc:controlfield[@tag='</xsl:text>
112 <xsl:value-of select="$tag"/>
113 <xsl:text>']</xsl:text>
115 <xslo:variable name="thesaurus_code1">
116 <xsl:attribute name="select">
117 <xsl:text>substring(., </xsl:text>
118 <xsl:value-of select="$offset + 1" />
119 <xsl:text>, </xsl:text>
120 <xsl:value-of select="$length" />
121 <xsl:text>)</xsl:text>
124 <xsl:variable name="alt_select">
125 <xsl:text>//marc:datafield[@tag='</xsl:text>
126 <xsl:value-of select="$detail_tag"/>
127 <xsl:text>']/marc:subfield[@code='</xsl:text>
128 <xsl:value-of select="$detail_subfields"/>
129 <xsl:text>']</xsl:text>
131 <xslo:variable name="full_thesaurus_code">
133 <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
134 <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
135 <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
136 <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
137 <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
138 <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
139 <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
140 <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
141 <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
142 <xslo:when test="$thesaurus_code1 = 'z'">
145 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
147 <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
150 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
153 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
157 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
158 <xslo:value-of select="$full_thesaurus_code"/>
163 <xsl:template name="handle-index-leader">
164 <xsl:if test="kohaidx:index_leader">
165 <xslo:template match="marc:leader">
166 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
171 <xsl:template match="kohaidx:index_leader" mode="secondary">
172 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
173 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
174 <xsl:variable name="indexes">
175 <xsl:call-template name="get-target-indexes"/>
178 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
180 <xsl:attribute name="select">
181 <xsl:text>substring(., </xsl:text>
182 <xsl:value-of select="$offset + 1" />
183 <xsl:text>, </xsl:text>
184 <xsl:value-of select="$length" />
185 <xsl:text>)</xsl:text>
191 <xsl:template name="handle-index-control-field">
192 <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
194 <xsl:attribute name="match">
195 <xsl:text>marc:controlfield[@tag='</xsl:text>
196 <xsl:value-of select="@tag"/>
197 <xsl:text>']</xsl:text>
199 <xsl:for-each select="key('index_control_field_tag', @tag)">
200 <xsl:call-template name="handle-one-index-control-field"/>
206 <xsl:template name="handle-one-index-control-field">
207 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
208 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
209 <xsl:variable name="indexes">
210 <xsl:call-template name="get-target-indexes"/>
213 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
215 <xsl:attribute name="select">
217 <xsl:when test="@length">
218 <xsl:text>substring(., </xsl:text>
219 <xsl:value-of select="$offset + 1" />
220 <xsl:text>, </xsl:text>
221 <xsl:value-of select="$length"/>
222 <xsl:text>)</xsl:text>
225 <xsl:text>.</xsl:text>
233 <xsl:template name="handle-index-subfields">
234 <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
235 <xslo:template mode="index_subfields">
236 <xsl:attribute name="match">
237 <xsl:text>marc:datafield[@tag='</xsl:text>
238 <xsl:value-of select="@tag"/>
239 <xsl:text>']</xsl:text>
241 <xsl:for-each select="key('index_subfields_tag', @tag)">
242 <xsl:call-template name="handle-one-index-subfields"/>
248 <xsl:template name="handle-one-index-subfields">
249 <xsl:variable name="indexes">
250 <xsl:call-template name="get-target-indexes"/>
252 <xslo:for-each select="marc:subfield">
254 <xsl:attribute name="test">
255 <xsl:text>contains('</xsl:text>
256 <xsl:value-of select="@subfields"/>
257 <xsl:text>', @code)</xsl:text>
260 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
261 <xslo:value-of select="."/>
267 <xsl:template name="handle-index-data-field">
268 <xsl:for-each select="//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
269 <xslo:template mode="index_data_field">
270 <xsl:attribute name="match">
271 <xsl:text>marc:datafield[@tag='</xsl:text>
272 <xsl:value-of select="@tag"/>
273 <xsl:text>']</xsl:text>
275 <xsl:for-each select="key('index_data_field_tag', @tag)">
276 <xsl:call-template name="handle-one-data-field"/>
282 <xsl:template name="handle-one-data-field">
283 <xsl:variable name="indexes">
284 <xsl:call-template name="get-target-indexes"/>
287 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
288 <xslo:variable name="raw_heading">
289 <xslo:for-each select="marc:subfield">
290 <xslo:if test="position() > 1">
291 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
293 <xslo:value-of select="."/>
296 <xslo:value-of select="normalize-space($raw_heading)"/>
300 <xsl:template name="handle-index-heading">
301 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
302 <xslo:template mode="index_heading">
303 <xsl:attribute name="match">
304 <xsl:text>marc:datafield[@tag='</xsl:text>
305 <xsl:value-of select="@tag"/>
306 <xsl:text>']</xsl:text>
308 <xsl:for-each select="key('index_heading_tag', @tag)">
309 <xsl:call-template name="handle-one-index-heading"/>
315 <xsl:template name="handle-one-index-heading">
316 <xsl:variable name="indexes">
317 <xsl:call-template name="get-target-indexes"/>
320 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
321 <xslo:variable name="raw_heading">
322 <xslo:for-each select="marc:subfield">
324 <xsl:attribute name="test">
325 <xsl:text>contains('</xsl:text>
326 <xsl:value-of select="@subfields"/>
327 <xsl:text>', @code)</xsl:text>
329 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
330 <xslo:if test="position() > 1">
333 <xsl:attribute name="test">
334 <xsl:text>contains('</xsl:text>
335 <xsl:value-of select="@subdivisions"/>
336 <xsl:text>', @code)</xsl:text>
338 <xslo:text>--</xslo:text>
341 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
345 <xslo:value-of select="."/>
349 <xslo:value-of select="normalize-space($raw_heading)"/>
353 <xsl:template name="handle-index-match-heading">
354 <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
355 <xslo:template mode="index_match_heading">
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_match_heading_tag', @tag)">
362 <xsl:call-template name="handle-one-index-match-heading"/>
368 <xsl:template name="handle-one-index-match-heading">
369 <xsl:variable name="indexes">
370 <xsl:call-template name="get-target-indexes"/>
373 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
374 <xslo:variable name="raw_heading">
375 <xslo:for-each select="marc:subfield">
377 <xsl:attribute name="test">
378 <xsl:text>contains('</xsl:text>
379 <xsl:value-of select="@subfields"/>
380 <xsl:text>', @code)</xsl:text>
382 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
383 <xslo:if test="position() > 1">
386 <xsl:attribute name="test">
387 <xsl:text>contains('</xsl:text>
388 <xsl:value-of select="@subdivisions"/>
389 <xsl:text>', @code)</xsl:text>
393 <xsl:attribute name="test">
394 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
396 <xslo:text> generalsubdiv </xslo:text>
399 <xsl:attribute name="test">
400 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
402 <xslo:text> formsubdiv </xslo:text>
405 <xsl:attribute name="test">
406 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
408 <xslo:text> chronologicalsubdiv </xslo:text>
411 <xsl:attribute name="test">
412 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
414 <xslo:text> geographicsubdiv </xslo:text>
419 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
423 <xslo:call-template name="chopPunctuation">
424 <xslo:with-param name="chopString">
425 <xslo:value-of select="."/>
427 </xslo:call-template>
431 <xslo:value-of select="normalize-space($raw_heading)"/>
435 <xsl:template name="get-target-indexes">
436 <xsl:for-each select="kohaidx:target_index">
437 <xsl:value-of select="." /><xsl:text> </xsl:text>