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.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"/>
19 <xsl:template match="kohaidx:index_defs">
20 <xslo:stylesheet version="1.0">
21 <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
22 <xslo:template match="text()"/>
23 <xslo:template match="text()" mode="index_subfields"/>
24 <xslo:template match="text()" mode="index_heading"/>
25 <xslo:template match="text()" mode="index_subject_thesaurus"/>
26 <xslo:template match="/">
27 <xslo:if test="marc:collection">
29 <xslo:apply-templates select="marc:collection/marc:record"/>
32 <xslo:if test="marc:record">
33 <xslo:apply-templates select="marc:record"/>
37 <xslo:template match="marc:record">
38 <xslo:variable name="controlField001" select="normalize-space(marc:controlfield[@tag='001'])"/>
39 <z:record type="update">
40 <xslo:attribute name="z:id"><xslo:value-of select="$controlField001"/></xslo:attribute>
41 <xslo:apply-templates/>
42 <xslo:apply-templates mode="index_subfields"/>
43 <xslo:apply-templates mode="index_heading"/>
44 <xslo:apply-templates mode="index_subject_thesaurus"/>
48 <xsl:call-template name="handle-index-leader"/>
49 <xsl:call-template name="handle-index-control-field"/>
50 <xsl:call-template name="handle-index-subfields"/>
51 <xsl:call-template name="handle-index-heading"/>
52 <xsl:apply-templates/>
56 <xsl:template match="kohaidx:index_subject_thesaurus">
57 <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
58 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
59 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
60 <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
61 <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
62 <xsl:variable name="indexes">
63 <xsl:call-template name="get-target-indexes"/>
65 <xslo:template mode="index_subject_thesaurus">
66 <xsl:attribute name="match">
67 <xsl:text>marc:controlfield[@tag='</xsl:text>
68 <xsl:value-of select="$tag"/>
69 <xsl:text>']</xsl:text>
71 <xslo:variable name="thesaurus_code1">
72 <xsl:attribute name="select">
73 <xsl:text>substring(., </xsl:text>
74 <xsl:value-of select="$offset + 1" />
75 <xsl:text>, </xsl:text>
76 <xsl:value-of select="$length" />
77 <xsl:text>)</xsl:text>
80 <xsl:variable name="alt_select">
81 <xsl:text>//marc:datafield[@tag='</xsl:text>
82 <xsl:value-of select="$detail_tag"/>
83 <xsl:text>']/marc:subfield[@code='</xsl:text>
84 <xsl:value-of select="$detail_subfields"/>
85 <xsl:text>']</xsl:text>
87 <xslo:variable name="full_thesaurus_code">
89 <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
90 <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
91 <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
92 <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
93 <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
94 <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
95 <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
96 <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
97 <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
98 <xslo:when test="$thesaurus_code1 = 'z'">
101 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
103 <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
106 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
109 <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
113 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
114 <xslo:value-of select="$full_thesaurus_code"/>
119 <xsl:template name="handle-index-leader">
120 <xsl:if test="kohaidx:index_leader">
121 <xslo:template match="marc:leader">
122 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
127 <xsl:template match="kohaidx:index_leader" mode="secondary">
128 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
129 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
130 <xsl:variable name="indexes">
131 <xsl:call-template name="get-target-indexes"/>
134 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
136 <xsl:attribute name="select">
137 <xsl:text>substring(., </xsl:text>
138 <xsl:value-of select="$offset + 1" />
139 <xsl:text>, </xsl:text>
140 <xsl:value-of select="$length" />
141 <xsl:text>)</xsl:text>
147 <xsl:template name="handle-index-control-field">
148 <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
150 <xsl:attribute name="match">
151 <xsl:text>marc:controlfield[@tag='</xsl:text>
152 <xsl:value-of select="@tag"/>
153 <xsl:text>']</xsl:text>
155 <xsl:for-each select="key('index_control_field_tag', @tag)">
156 <xsl:call-template name="handle-one-index-control-field"/>
162 <xsl:template name="handle-one-index-control-field">
163 <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
164 <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
165 <xsl:variable name="indexes">
166 <xsl:call-template name="get-target-indexes"/>
169 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
171 <xsl:attribute name="select">
173 <xsl:when test="@length">
174 <xsl:text>substring(., </xsl:text>
175 <xsl:value-of select="$offset + 1" />
176 <xsl:text>, </xsl:text>
177 <xsl:value-of select="$length"/>
178 <xsl:text>)</xsl:text>
181 <xsl:text>.</xsl:text>
189 <xsl:template name="handle-index-subfields">
190 <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
191 <xslo:template mode="index_subfields">
192 <xsl:attribute name="match">
193 <xsl:text>marc:datafield[@tag='</xsl:text>
194 <xsl:value-of select="@tag"/>
195 <xsl:text>']</xsl:text>
197 <xsl:for-each select="key('index_subfields_tag', @tag)">
198 <xsl:call-template name="handle-one-index-subfields"/>
204 <xsl:template name="handle-one-index-subfields">
205 <xsl:variable name="indexes">
206 <xsl:call-template name="get-target-indexes"/>
208 <xslo:for-each select="marc:subfield">
210 <xsl:attribute name="test">
211 <xsl:text>contains('</xsl:text>
212 <xsl:value-of select="@subfields"/>
213 <xsl:text>', @code)</xsl:text>
216 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
217 <xslo:value-of select="."/>
223 <xsl:template name="handle-index-heading">
224 <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
225 <xslo:template mode="index_heading">
226 <xsl:attribute name="match">
227 <xsl:text>marc:datafield[@tag='</xsl:text>
228 <xsl:value-of select="@tag"/>
229 <xsl:text>']</xsl:text>
231 <xsl:for-each select="key('index_heading_tag', @tag)">
232 <xsl:call-template name="handle-one-index-heading"/>
238 <xsl:template name="handle-one-index-heading">
239 <xsl:variable name="indexes">
240 <xsl:call-template name="get-target-indexes"/>
243 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
244 <xslo:variable name="raw_heading">
245 <xslo:for-each select="marc:subfield">
247 <xsl:attribute name="test">
248 <xsl:text>contains('</xsl:text>
249 <xsl:value-of select="@subfields"/>
250 <xsl:text>', @code)</xsl:text>
252 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
253 <xslo:if test="position() > 1">
256 <xsl:attribute name="test">
257 <xsl:text>contains('</xsl:text>
258 <xsl:value-of select="@subdivisions"/>
259 <xsl:text>', @code)</xsl:text>
261 <xslo:text>--</xslo:text>
264 <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way to specify a space -->
268 <xslo:value-of select="."/>
272 <xslo:value-of select="normalize-space($raw_heading)"/>
276 <xsl:template name="get-target-indexes">
277 <xsl:for-each select="kohaidx:target_index">
278 <xsl:value-of select="." /><xsl:text> </xsl:text>