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">
21 <xslo:stylesheet version="1.0">
22 <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
23 <xslo:template match="text()"/>
24 <xslo:template match="text()" mode="index_subfields"/>
25 <xslo:template match="text()" mode="index_heading"/>
26 <xslo:template match="text()" mode="index_match_heading"/>
27 <xslo:template match="text()" mode="index_subject_thesaurus"/>
28 <xslo:template match="/">
29 <xslo:if test="marc:collection">
31 <xslo:apply-templates select="marc:collection/marc:record"/>
34 <xslo:if test="marc:record">
35 <xslo:apply-templates select="marc:record"/>
39 <xslo:template match="marc:record">
40 <xslo:variable name="controlField001" select="normalize-space(marc:controlfield[@tag='001'])"/>
41 <z:record type="update">
42 <xslo:attribute name="z:id"><xslo:value-of select="$controlField001"/></xslo:attribute>
43 <xslo:apply-templates/>
44 <xslo:apply-templates mode="index_subfields"/>
45 <xslo:apply-templates mode="index_heading"/>
46 <xslo:apply-templates mode="index_match_heading"/>
47 <xslo:apply-templates mode="index_subject_thesaurus"/>
51 <xsl:call-template name="handle-index-leader"/>
52 <xsl:call-template name="handle-index-control-field"/>
53 <xsl:call-template name="handle-index-subfields"/>
54 <xsl:call-template name="handle-index-heading"/>
55 <xsl:call-template name="handle-index-match-heading"/>
56 <xsl:apply-templates/>
57 <xslo:template match="*">
58 <z:index name="Any:w Any:p">
59 <xslo:value-of select="."/>
65 <!-- map kohaidx:var to stylesheet variables -->
66 <xsl:template match="kohaidx:var">
68 <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
69 <xsl:value-of select="."/>
73 <xsl:template match="kohaidx:index_subject_thesaurus">
74 <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
75 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
76 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
77 <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
78 <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
79 <xsl:variable name="indexes">
80 <xsl:call-template name="get-target-indexes"/>
82 <xslo:template mode="index_subject_thesaurus">
83 <xsl:attribute name="match">
84 <xsl:text>marc:controlfield[@tag='</xsl:text>
85 <xsl:value-of select="$tag"/>
86 <xsl:text>']</xsl:text>
88 <xslo:variable name="thesaurus_code1">
89 <xsl:attribute name="select">
90 <xsl:text>substring(., </xsl:text>
91 <xsl:value-of select="$offset + 1" />
92 <xsl:text>, </xsl:text>
93 <xsl:value-of select="$length" />
94 <xsl:text>)</xsl:text>
97 <xsl:variable name="alt_select">
98 <xsl:text>//marc:datafield[@tag='</xsl:text>
99 <xsl:value-of select="$detail_tag"/>
100 <xsl:text>']/marc:subfield[@code='</xsl:text>
101 <xsl:value-of select="$detail_subfields"/>
102 <xsl:text>']</xsl:text>
104 <xslo:variable name="full_thesaurus_code">
106 <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
107 <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
108 <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
109 <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
110 <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
111 <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
112 <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
113 <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
114 <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
115 <xslo:when test="$thesaurus_code1 = 'z'">
118 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
120 <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
123 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
126 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
130 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
131 <xslo:value-of select="$full_thesaurus_code"/>
136 <xsl:template name="handle-index-leader">
137 <xsl:if test="kohaidx:index_leader">
138 <xslo:template match="marc:leader">
139 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
144 <xsl:template match="kohaidx:index_leader" mode="secondary">
145 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
146 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
147 <xsl:variable name="indexes">
148 <xsl:call-template name="get-target-indexes"/>
151 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
153 <xsl:attribute name="select">
154 <xsl:text>substring(., </xsl:text>
155 <xsl:value-of select="$offset + 1" />
156 <xsl:text>, </xsl:text>
157 <xsl:value-of select="$length" />
158 <xsl:text>)</xsl:text>
164 <xsl:template name="handle-index-control-field">
165 <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
167 <xsl:attribute name="match">
168 <xsl:text>marc:controlfield[@tag='</xsl:text>
169 <xsl:value-of select="@tag"/>
170 <xsl:text>']</xsl:text>
172 <xsl:for-each select="key('index_control_field_tag', @tag)">
173 <xsl:call-template name="handle-one-index-control-field"/>
179 <xsl:template name="handle-one-index-control-field">
180 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
181 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
182 <xsl:variable name="indexes">
183 <xsl:call-template name="get-target-indexes"/>
186 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
188 <xsl:attribute name="select">
190 <xsl:when test="@length">
191 <xsl:text>substring(., </xsl:text>
192 <xsl:value-of select="$offset + 1" />
193 <xsl:text>, </xsl:text>
194 <xsl:value-of select="$length"/>
195 <xsl:text>)</xsl:text>
198 <xsl:text>.</xsl:text>
206 <xsl:template name="handle-index-subfields">
207 <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
208 <xslo:template mode="index_subfields">
209 <xsl:attribute name="match">
210 <xsl:text>marc:datafield[@tag='</xsl:text>
211 <xsl:value-of select="@tag"/>
212 <xsl:text>']</xsl:text>
214 <xsl:for-each select="key('index_subfields_tag', @tag)">
215 <xsl:call-template name="handle-one-index-subfields"/>
221 <xsl:template name="handle-one-index-subfields">
222 <xsl:variable name="indexes">
223 <xsl:call-template name="get-target-indexes"/>
225 <xslo:for-each select="marc:subfield">
227 <xsl:attribute name="test">
228 <xsl:text>contains('</xsl:text>
229 <xsl:value-of select="@subfields"/>
230 <xsl:text>', @code)</xsl:text>
233 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
234 <xslo:value-of select="."/>
240 <xsl:template name="handle-index-heading">
241 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
242 <xslo:template mode="index_heading">
243 <xsl:attribute name="match">
244 <xsl:text>marc:datafield[@tag='</xsl:text>
245 <xsl:value-of select="@tag"/>
246 <xsl:text>']</xsl:text>
248 <xsl:for-each select="key('index_heading_tag', @tag)">
249 <xsl:call-template name="handle-one-index-heading"/>
255 <xsl:template name="handle-one-index-heading">
256 <xsl:variable name="indexes">
257 <xsl:call-template name="get-target-indexes"/>
260 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
261 <xslo:variable name="raw_heading">
262 <xslo:for-each select="marc:subfield">
264 <xsl:attribute name="test">
265 <xsl:text>contains('</xsl:text>
266 <xsl:value-of select="@subfields"/>
267 <xsl:text>', @code)</xsl:text>
269 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
270 <xslo:if test="position() > 1">
273 <xsl:attribute name="test">
274 <xsl:text>contains('</xsl:text>
275 <xsl:value-of select="@subdivisions"/>
276 <xsl:text>', @code)</xsl:text>
278 <xslo:text>--</xslo:text>
281 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
285 <xslo:value-of select="."/>
289 <xslo:value-of select="normalize-space($raw_heading)"/>
293 <xsl:template name="handle-index-match-heading">
294 <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
295 <xslo:template mode="index_match_heading">
296 <xsl:attribute name="match">
297 <xsl:text>marc:datafield[@tag='</xsl:text>
298 <xsl:value-of select="@tag"/>
299 <xsl:text>']</xsl:text>
301 <xsl:for-each select="key('index_match_heading_tag', @tag)">
302 <xsl:call-template name="handle-one-index-match-heading"/>
308 <xsl:template name="handle-one-index-match-heading">
309 <xsl:variable name="indexes">
310 <xsl:call-template name="get-target-indexes"/>
313 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
314 <xslo:variable name="raw_heading">
315 <xslo:for-each select="marc:subfield">
317 <xsl:attribute name="test">
318 <xsl:text>contains('</xsl:text>
319 <xsl:value-of select="@subfields"/>
320 <xsl:text>', @code)</xsl:text>
322 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
323 <xslo:if test="position() > 1">
326 <xsl:attribute name="test">
327 <xsl:text>contains('</xsl:text>
328 <xsl:value-of select="@subdivisions"/>
329 <xsl:text>', @code)</xsl:text>
333 <xsl:attribute name="test">
334 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
336 <xslo:text> generalsubdiv </xslo:text>
339 <xsl:attribute name="test">
340 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
342 <xslo:text> formsubdiv </xslo:text>
345 <xsl:attribute name="test">
346 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
348 <xslo:text> chronologicalsubdiv </xslo:text>
351 <xsl:attribute name="test">
352 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
354 <xslo:text> geographicsubdiv </xslo:text>
359 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
363 <xslo:value-of select="."/>
367 <xslo:value-of select="normalize-space($raw_heading)"/>
371 <xsl:template name="get-target-indexes">
372 <xsl:for-each select="kohaidx:target_index">
373 <xsl:value-of select="." /><xsl:text> </xsl:text>