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="."/>
73 <!-- map kohaidx:var to stylesheet variables -->
74 <xsl:template match="kohaidx:var">
76 <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
77 <xsl:value-of select="."/>
81 <xsl:template match="kohaidx:index_subject_thesaurus">
82 <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
83 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
84 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
85 <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
86 <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
87 <xsl:variable name="indexes">
88 <xsl:call-template name="get-target-indexes"/>
90 <xslo:template mode="index_subject_thesaurus">
91 <xsl:attribute name="match">
92 <xsl:text>marc:controlfield[@tag='</xsl:text>
93 <xsl:value-of select="$tag"/>
94 <xsl:text>']</xsl:text>
96 <xslo:variable name="thesaurus_code1">
97 <xsl:attribute name="select">
98 <xsl:text>substring(., </xsl:text>
99 <xsl:value-of select="$offset + 1" />
100 <xsl:text>, </xsl:text>
101 <xsl:value-of select="$length" />
102 <xsl:text>)</xsl:text>
105 <xsl:variable name="alt_select">
106 <xsl:text>//marc:datafield[@tag='</xsl:text>
107 <xsl:value-of select="$detail_tag"/>
108 <xsl:text>']/marc:subfield[@code='</xsl:text>
109 <xsl:value-of select="$detail_subfields"/>
110 <xsl:text>']</xsl:text>
112 <xslo:variable name="full_thesaurus_code">
114 <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
115 <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
116 <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
117 <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
118 <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
119 <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
120 <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
121 <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
122 <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
123 <xslo:when test="$thesaurus_code1 = 'z'">
126 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
128 <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
131 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
134 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
138 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
139 <xslo:value-of select="$full_thesaurus_code"/>
144 <xsl:template name="handle-index-leader">
145 <xsl:if test="kohaidx:index_leader">
146 <xslo:template match="marc:leader">
147 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
152 <xsl:template match="kohaidx:index_leader" mode="secondary">
153 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
154 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
155 <xsl:variable name="indexes">
156 <xsl:call-template name="get-target-indexes"/>
159 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
161 <xsl:attribute name="select">
162 <xsl:text>substring(., </xsl:text>
163 <xsl:value-of select="$offset + 1" />
164 <xsl:text>, </xsl:text>
165 <xsl:value-of select="$length" />
166 <xsl:text>)</xsl:text>
172 <xsl:template name="handle-index-control-field">
173 <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
175 <xsl:attribute name="match">
176 <xsl:text>marc:controlfield[@tag='</xsl:text>
177 <xsl:value-of select="@tag"/>
178 <xsl:text>']</xsl:text>
180 <xsl:for-each select="key('index_control_field_tag', @tag)">
181 <xsl:call-template name="handle-one-index-control-field"/>
187 <xsl:template name="handle-one-index-control-field">
188 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
189 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
190 <xsl:variable name="indexes">
191 <xsl:call-template name="get-target-indexes"/>
194 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
196 <xsl:attribute name="select">
198 <xsl:when test="@length">
199 <xsl:text>substring(., </xsl:text>
200 <xsl:value-of select="$offset + 1" />
201 <xsl:text>, </xsl:text>
202 <xsl:value-of select="$length"/>
203 <xsl:text>)</xsl:text>
206 <xsl:text>.</xsl:text>
214 <xsl:template name="handle-index-subfields">
215 <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
216 <xslo:template mode="index_subfields">
217 <xsl:attribute name="match">
218 <xsl:text>marc:datafield[@tag='</xsl:text>
219 <xsl:value-of select="@tag"/>
220 <xsl:text>']</xsl:text>
222 <xsl:for-each select="key('index_subfields_tag', @tag)">
223 <xsl:call-template name="handle-one-index-subfields"/>
229 <xsl:template name="handle-one-index-subfields">
230 <xsl:variable name="indexes">
231 <xsl:call-template name="get-target-indexes"/>
233 <xslo:for-each select="marc:subfield">
235 <xsl:attribute name="test">
236 <xsl:text>contains('</xsl:text>
237 <xsl:value-of select="@subfields"/>
238 <xsl:text>', @code)</xsl:text>
241 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
242 <xslo:value-of select="."/>
248 <xsl:template name="handle-index-heading">
249 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
250 <xslo:template mode="index_heading">
251 <xsl:attribute name="match">
252 <xsl:text>marc:datafield[@tag='</xsl:text>
253 <xsl:value-of select="@tag"/>
254 <xsl:text>']</xsl:text>
256 <xsl:for-each select="key('index_heading_tag', @tag)">
257 <xsl:call-template name="handle-one-index-heading"/>
263 <xsl:template name="handle-one-index-heading">
264 <xsl:variable name="indexes">
265 <xsl:call-template name="get-target-indexes"/>
268 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
269 <xslo:variable name="raw_heading">
270 <xslo:for-each select="marc:subfield">
272 <xsl:attribute name="test">
273 <xsl:text>contains('</xsl:text>
274 <xsl:value-of select="@subfields"/>
275 <xsl:text>', @code)</xsl:text>
277 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
278 <xslo:if test="position() > 1">
281 <xsl:attribute name="test">
282 <xsl:text>contains('</xsl:text>
283 <xsl:value-of select="@subdivisions"/>
284 <xsl:text>', @code)</xsl:text>
286 <xslo:text>--</xslo:text>
289 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
293 <xslo:value-of select="."/>
297 <xslo:value-of select="normalize-space($raw_heading)"/>
301 <xsl:template name="handle-index-match-heading">
302 <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
303 <xslo:template mode="index_match_heading">
304 <xsl:attribute name="match">
305 <xsl:text>marc:datafield[@tag='</xsl:text>
306 <xsl:value-of select="@tag"/>
307 <xsl:text>']</xsl:text>
309 <xsl:for-each select="key('index_match_heading_tag', @tag)">
310 <xsl:call-template name="handle-one-index-match-heading"/>
316 <xsl:template name="handle-one-index-match-heading">
317 <xsl:variable name="indexes">
318 <xsl:call-template name="get-target-indexes"/>
321 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
322 <xslo:variable name="raw_heading">
323 <xslo:for-each select="marc:subfield">
325 <xsl:attribute name="test">
326 <xsl:text>contains('</xsl:text>
327 <xsl:value-of select="@subfields"/>
328 <xsl:text>', @code)</xsl:text>
330 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
331 <xslo:if test="position() > 1">
334 <xsl:attribute name="test">
335 <xsl:text>contains('</xsl:text>
336 <xsl:value-of select="@subdivisions"/>
337 <xsl:text>', @code)</xsl:text>
341 <xsl:attribute name="test">
342 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
344 <xslo:text> generalsubdiv </xslo:text>
347 <xsl:attribute name="test">
348 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
350 <xslo:text> formsubdiv </xslo:text>
353 <xsl:attribute name="test">
354 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
356 <xslo:text> chronologicalsubdiv </xslo:text>
359 <xsl:attribute name="test">
360 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
362 <xslo:text> geographicsubdiv </xslo:text>
367 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
371 <xslo:value-of select="."/>
375 <xslo:value-of select="normalize-space($raw_heading)"/>
379 <xsl:template name="get-target-indexes">
380 <xsl:for-each select="kohaidx:target_index">
381 <xsl:value-of select="." /><xsl:text> </xsl:text>