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_match_heading_tag" match="kohaidx:index_match_heading" use="@tag"/>
20 <xsl:template match="kohaidx:index_defs">
22 This file has been automatically generated from a Koha index definition file
23 with the stylesheet koha-indexdefs-to-zebra.xsl. Do not manually edit this file,
24 as it may be overwritten. To regenerate, edit the appropriate Koha index
25 definition file (probably something like authority-koha-indexdefs.xml) and run:
26 `xsltproc koha-indexdefs-to-zebra.xsl authority-koha-indexdefs.xml >
27 authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
29 <xslo:stylesheet version="1.0">
30 <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
31 <xslo:template match="text()"/>
32 <xslo:template match="text()" mode="index_subfields"/>
33 <xslo:template match="text()" mode="index_heading"/>
34 <xslo:template match="text()" mode="index_match_heading"/>
35 <xslo:template match="text()" mode="index_subject_thesaurus"/>
36 <xslo:template match="/">
37 <xslo:if test="marc:collection">
39 <xslo:apply-templates select="marc:collection/marc:record"/>
42 <xslo:if test="marc:record">
43 <xslo:apply-templates select="marc:record"/>
47 <xslo:template match="marc:record">
48 <xslo:variable name="controlField001" select="normalize-space(marc:controlfield[@tag='001'])"/>
49 <z:record type="update">
50 <xslo:attribute name="z:id"><xslo:value-of select="$controlField001"/></xslo:attribute>
51 <xslo:apply-templates/>
52 <xslo:apply-templates mode="index_subfields"/>
53 <xslo:apply-templates mode="index_heading"/>
54 <xslo:apply-templates mode="index_match_heading"/>
55 <xslo:apply-templates mode="index_subject_thesaurus"/>
59 <xsl:call-template name="handle-index-leader"/>
60 <xsl:call-template name="handle-index-control-field"/>
61 <xsl:call-template name="handle-index-subfields"/>
62 <xsl:call-template name="handle-index-heading"/>
63 <xsl:call-template name="handle-index-match-heading"/>
64 <xsl:apply-templates/>
65 <xslo:template match="*">
66 <z:index name="Any:w Any:p">
67 <xslo:value-of select="."/>
70 <xslo:template name="chopPunctuation">
71 <xslo:param name="chopString"/>
72 <xslo:variable name="length" select="string-length($chopString)"/>
74 <xslo:when test="$length=0"/>
75 <xslo:when test="contains('-,.:=;!%/', substring($chopString,$length,1))">
76 <xslo:call-template name="chopPunctuation">
77 <xslo:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
80 <xslo:when test="not($chopString)"/>
81 <xslo:otherwise><xslo:value-of select="$chopString"/></xslo:otherwise>
83 <xslo:text> </xslo:text>
88 <!-- map kohaidx:var to stylesheet variables -->
89 <xsl:template match="kohaidx:var">
91 <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
92 <xsl:value-of select="."/>
96 <xsl:template match="kohaidx:index_subject_thesaurus">
97 <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
98 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
99 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
100 <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
101 <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
102 <xsl:variable name="indexes">
103 <xsl:call-template name="get-target-indexes"/>
105 <xslo:template mode="index_subject_thesaurus">
106 <xsl:attribute name="match">
107 <xsl:text>marc:controlfield[@tag='</xsl:text>
108 <xsl:value-of select="$tag"/>
109 <xsl:text>']</xsl:text>
111 <xslo:variable name="thesaurus_code1">
112 <xsl:attribute name="select">
113 <xsl:text>substring(., </xsl:text>
114 <xsl:value-of select="$offset + 1" />
115 <xsl:text>, </xsl:text>
116 <xsl:value-of select="$length" />
117 <xsl:text>)</xsl:text>
120 <xsl:variable name="alt_select">
121 <xsl:text>//marc:datafield[@tag='</xsl:text>
122 <xsl:value-of select="$detail_tag"/>
123 <xsl:text>']/marc:subfield[@code='</xsl:text>
124 <xsl:value-of select="$detail_subfields"/>
125 <xsl:text>']</xsl:text>
127 <xslo:variable name="full_thesaurus_code">
129 <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
130 <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
131 <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
132 <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
133 <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
134 <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
135 <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
136 <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
137 <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
138 <xslo:when test="$thesaurus_code1 = 'z'">
141 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
143 <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
146 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
149 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
153 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
154 <xslo:value-of select="$full_thesaurus_code"/>
159 <xsl:template name="handle-index-leader">
160 <xsl:if test="kohaidx:index_leader">
161 <xslo:template match="marc:leader">
162 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
167 <xsl:template match="kohaidx:index_leader" mode="secondary">
168 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
169 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
170 <xsl:variable name="indexes">
171 <xsl:call-template name="get-target-indexes"/>
174 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
176 <xsl:attribute name="select">
177 <xsl:text>substring(., </xsl:text>
178 <xsl:value-of select="$offset + 1" />
179 <xsl:text>, </xsl:text>
180 <xsl:value-of select="$length" />
181 <xsl:text>)</xsl:text>
187 <xsl:template name="handle-index-control-field">
188 <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
190 <xsl:attribute name="match">
191 <xsl:text>marc:controlfield[@tag='</xsl:text>
192 <xsl:value-of select="@tag"/>
193 <xsl:text>']</xsl:text>
195 <xsl:for-each select="key('index_control_field_tag', @tag)">
196 <xsl:call-template name="handle-one-index-control-field"/>
202 <xsl:template name="handle-one-index-control-field">
203 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
204 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
205 <xsl:variable name="indexes">
206 <xsl:call-template name="get-target-indexes"/>
209 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
211 <xsl:attribute name="select">
213 <xsl:when test="@length">
214 <xsl:text>substring(., </xsl:text>
215 <xsl:value-of select="$offset + 1" />
216 <xsl:text>, </xsl:text>
217 <xsl:value-of select="$length"/>
218 <xsl:text>)</xsl:text>
221 <xsl:text>.</xsl:text>
229 <xsl:template name="handle-index-subfields">
230 <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
231 <xslo:template mode="index_subfields">
232 <xsl:attribute name="match">
233 <xsl:text>marc:datafield[@tag='</xsl:text>
234 <xsl:value-of select="@tag"/>
235 <xsl:text>']</xsl:text>
237 <xsl:for-each select="key('index_subfields_tag', @tag)">
238 <xsl:call-template name="handle-one-index-subfields"/>
244 <xsl:template name="handle-one-index-subfields">
245 <xsl:variable name="indexes">
246 <xsl:call-template name="get-target-indexes"/>
248 <xslo:for-each select="marc:subfield">
250 <xsl:attribute name="test">
251 <xsl:text>contains('</xsl:text>
252 <xsl:value-of select="@subfields"/>
253 <xsl:text>', @code)</xsl:text>
256 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
257 <xslo:value-of select="."/>
263 <xsl:template name="handle-index-heading">
264 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
265 <xslo:template mode="index_heading">
266 <xsl:attribute name="match">
267 <xsl:text>marc:datafield[@tag='</xsl:text>
268 <xsl:value-of select="@tag"/>
269 <xsl:text>']</xsl:text>
271 <xsl:for-each select="key('index_heading_tag', @tag)">
272 <xsl:call-template name="handle-one-index-heading"/>
278 <xsl:template name="handle-one-index-heading">
279 <xsl:variable name="indexes">
280 <xsl:call-template name="get-target-indexes"/>
283 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
284 <xslo:variable name="raw_heading">
285 <xslo:for-each select="marc:subfield">
287 <xsl:attribute name="test">
288 <xsl:text>contains('</xsl:text>
289 <xsl:value-of select="@subfields"/>
290 <xsl:text>', @code)</xsl:text>
292 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
293 <xslo:if test="position() > 1">
296 <xsl:attribute name="test">
297 <xsl:text>contains('</xsl:text>
298 <xsl:value-of select="@subdivisions"/>
299 <xsl:text>', @code)</xsl:text>
301 <xslo:text>--</xslo:text>
304 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
308 <xslo:value-of select="."/>
312 <xslo:value-of select="normalize-space($raw_heading)"/>
316 <xsl:template name="handle-index-match-heading">
317 <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
318 <xslo:template mode="index_match_heading">
319 <xsl:attribute name="match">
320 <xsl:text>marc:datafield[@tag='</xsl:text>
321 <xsl:value-of select="@tag"/>
322 <xsl:text>']</xsl:text>
324 <xsl:for-each select="key('index_match_heading_tag', @tag)">
325 <xsl:call-template name="handle-one-index-match-heading"/>
331 <xsl:template name="handle-one-index-match-heading">
332 <xsl:variable name="indexes">
333 <xsl:call-template name="get-target-indexes"/>
336 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
337 <xslo:variable name="raw_heading">
338 <xslo:for-each select="marc:subfield">
340 <xsl:attribute name="test">
341 <xsl:text>contains('</xsl:text>
342 <xsl:value-of select="@subfields"/>
343 <xsl:text>', @code)</xsl:text>
345 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
346 <xslo:if test="position() > 1">
349 <xsl:attribute name="test">
350 <xsl:text>contains('</xsl:text>
351 <xsl:value-of select="@subdivisions"/>
352 <xsl:text>', @code)</xsl:text>
356 <xsl:attribute name="test">
357 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
359 <xslo:text> generalsubdiv </xslo:text>
362 <xsl:attribute name="test">
363 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
365 <xslo:text> formsubdiv </xslo:text>
368 <xsl:attribute name="test">
369 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
371 <xslo:text> chronologicalsubdiv </xslo:text>
374 <xsl:attribute name="test">
375 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
377 <xslo:text> geographicsubdiv </xslo:text>
382 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
386 <xslo:call-template name="chopPunctuation">
387 <xslo:with-param name="chopString">
388 <xslo:value-of select="."/>
390 </xslo:call-template>
394 <xslo:value-of select="normalize-space($raw_heading)"/>
398 <xsl:template name="get-target-indexes">
399 <xsl:for-each select="kohaidx:target_index">
400 <xsl:value-of select="." /><xsl:text> </xsl:text>