]> git.koha-community.org Git - koha.git/blob - etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl
Bug 11232: Add new syntax for facets definition on koha-indexdefs-to-zebra.xsl
[koha.git] / etc / zebradb / xsl / koha-indexdefs-to-zebra.xsl
1 <?xml version='1.0'?>
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">
8
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()"/>
13
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_facet_tag"         match="kohaidx:facet"               use="@tag"/>
18     <xsl:key name="index_heading_tag"       match="kohaidx:index_heading"       use="@tag"/>
19     <xsl:key name="index_data_field_tag"    match="kohaidx:index_data_field"    use="@tag"/>
20     <xsl:key name="index_heading_conditional_tag" match="kohaidx:index_heading_conditional" use="@tag"/>
21     <xsl:key name="index_match_heading_tag" match="kohaidx:index_match_heading" use="@tag"/>
22
23     <xsl:template match="kohaidx:index_defs">
24     <xsl:comment>
25 This file has been automatically generated from a Koha index definition file
26 with the stylesheet koha-indexdefs-to-zebra.xsl. Do not manually edit this file,
27 as it may be overwritten. To regenerate, edit the appropriate Koha index
28 definition file (probably something like {biblio,authority}-koha-indexdefs.xml) and run:
29 `xsltproc koha-indexdefs-to-zebra.xsl {biblio,authority}-koha-indexdefs.xml >
30 {biblio,authority}-zebra-indexdefs.xsl` (substituting the appropriate file names).
31 </xsl:comment>
32         <xslo:stylesheet version="1.0">
33             <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
34             <xslo:template match="text()"/>
35             <xslo:template match="text()" mode="index_subfields"/>
36             <xslo:template match="text()" mode="index_data_field"/>
37             <xslo:template match="text()" mode="index_facets"/>
38             <xslo:template match="text()" mode="index_heading"/>
39             <xslo:template match="text()" mode="index_heading_conditional"/>
40             <xslo:template match="text()" mode="index_match_heading"/>
41             <xslo:template match="text()" mode="index_subject_thesaurus"/>
42             <xslo:template match="/">
43                 <xslo:if test="marc:collection">
44                     <collection>
45                         <xslo:apply-templates select="marc:collection/marc:record"/>
46                     </collection>
47                 </xslo:if>
48                 <xslo:if test="marc:record">
49                     <xslo:apply-templates select="marc:record"/>
50                 </xslo:if>
51             </xslo:template>
52
53             <xslo:template match="marc:record">
54                 <xslo:variable name="idfield">
55                     <xsl:attribute name="select">normalize-space(<xsl:value-of select="//id"/>)</xsl:attribute>
56                 </xslo:variable>
57                 <z:record type="update">
58                     <xslo:attribute name="z:id"><xslo:value-of select="$idfield"/></xslo:attribute>
59                     <xslo:apply-templates/>
60                     <xslo:apply-templates mode="index_subfields"/>
61                     <xslo:apply-templates mode="index_data_field"/>
62                     <xslo:apply-templates mode="index_facets"/>
63                     <xslo:apply-templates mode="index_heading"/>
64                     <xslo:apply-templates mode="index_heading_conditional"/>
65                     <xslo:apply-templates mode="index_match_heading"/>
66                     <xslo:apply-templates mode="index_subject_thesaurus"/>
67                     <xslo:apply-templates mode="index_all"/>
68                 </z:record>
69             </xslo:template>
70
71             <xsl:call-template name="handle-index-leader"/>
72             <xsl:call-template name="handle-index-control-field"/>
73             <xsl:call-template name="handle-index-subfields"/>
74             <xsl:call-template name="handle-index-data-field"/>
75             <xsl:call-template name="handle-index-facets"/>
76             <xsl:call-template name="handle-index-heading"/>
77             <xsl:call-template name="handle-index-heading-conditional"/>
78             <xsl:call-template name="handle-index-match-heading"/>
79             <xsl:apply-templates/>
80             <xslo:template mode="index_all" match="text()">
81                 <z:index name="Any:w Any:p">
82                     <xslo:value-of select="."/>
83                 </z:index>
84             </xslo:template>
85             <xslo:template name="chopPunctuation">
86             <xslo:param name="chopString"/>
87                 <xslo:variable name="length" select="string-length($chopString)"/>
88                 <xslo:choose>
89                 <xslo:when test="$length=0"/>
90                 <xslo:when test="contains('-,.:=;!%/', substring($chopString,$length,1))">
91                     <xslo:call-template name="chopPunctuation">
92                     <xslo:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
93                     </xslo:call-template>
94                 </xslo:when>
95                 <xslo:when test="not($chopString)"/>
96                 <xslo:otherwise><xslo:value-of select="$chopString"/></xslo:otherwise>
97                 </xslo:choose>
98                 <xslo:text> </xslo:text>
99             </xslo:template>
100         </xslo:stylesheet>
101     </xsl:template>
102
103     <!-- map kohaidx:var to stylesheet variables -->
104     <xsl:template match="kohaidx:var">
105         <xslo:variable>
106             <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
107             <xsl:value-of select="."/>
108         </xslo:variable>
109     </xsl:template>
110
111     <xsl:template match="kohaidx:index_subject_thesaurus">
112         <xsl:variable name="tag"><xsl:value-of select="@tag"/></xsl:variable>
113         <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
114         <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
115         <xsl:variable name="detail_tag"><xsl:value-of select="@detail_tag"/></xsl:variable>
116         <xsl:variable name="detail_subfields"><xsl:value-of select="@detail_subfields"/></xsl:variable>
117         <xsl:variable name="indexes">
118             <xsl:call-template name="get-target-indexes"/>
119         </xsl:variable>
120         <xslo:template mode="index_subject_thesaurus">
121             <xsl:attribute name="match">
122                 <xsl:text>marc:controlfield[@tag='</xsl:text>
123                 <xsl:value-of select="$tag"/>
124                 <xsl:text>']</xsl:text>
125             </xsl:attribute>
126             <xslo:variable name="thesaurus_code1">
127                 <xsl:attribute name="select">
128                     <xsl:text>substring(., </xsl:text>
129                     <xsl:value-of select="$offset + 1" />
130                     <xsl:text>, </xsl:text>
131                     <xsl:value-of select="$length" />
132                     <xsl:text>)</xsl:text>
133                 </xsl:attribute>
134             </xslo:variable>
135             <xsl:variable name="alt_select">
136                 <xsl:text>//marc:datafield[@tag='</xsl:text>
137                 <xsl:value-of select="$detail_tag"/>
138                 <xsl:text>']/marc:subfield[@code='</xsl:text>
139                 <xsl:value-of select="$detail_subfields"/>
140                 <xsl:text>']</xsl:text>
141             </xsl:variable>
142             <xslo:variable name="full_thesaurus_code">
143                 <xslo:choose>
144                     <xslo:when test="$thesaurus_code1 = 'a'"><xslo:text>lcsh</xslo:text></xslo:when>
145                     <xslo:when test="$thesaurus_code1 = 'b'"><xslo:text>lcac</xslo:text></xslo:when>
146                     <xslo:when test="$thesaurus_code1 = 'c'"><xslo:text>mesh</xslo:text></xslo:when>
147                     <xslo:when test="$thesaurus_code1 = 'd'"><xslo:text>nal</xslo:text></xslo:when>
148                     <xslo:when test="$thesaurus_code1 = 'k'"><xslo:text>cash</xslo:text></xslo:when>
149                     <xslo:when test="$thesaurus_code1 = 'n'"><xslo:text>notapplicable</xslo:text></xslo:when>
150                     <xslo:when test="$thesaurus_code1 = 'r'"><xslo:text>aat</xslo:text></xslo:when>
151                     <xslo:when test="$thesaurus_code1 = 's'"><xslo:text>sears</xslo:text></xslo:when>
152                     <xslo:when test="$thesaurus_code1 = 'v'"><xslo:text>rvm</xslo:text></xslo:when>
153                     <xslo:when test="$thesaurus_code1 = 'z'">
154                         <xslo:choose>
155                             <xslo:when>
156                                 <xsl:attribute name="test"><xsl:value-of select="$alt_select"/></xsl:attribute>
157                                 <xslo:value-of>
158                                     <xsl:attribute name="select"><xsl:value-of select="$alt_select"/></xsl:attribute>
159                                 </xslo:value-of>
160                             </xslo:when>
161                             <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
162                         </xslo:choose>
163                     </xslo:when>
164                     <xslo:otherwise><xslo:text>notdefined</xslo:text></xslo:otherwise>
165                 </xslo:choose>
166             </xslo:variable>
167             <z:index>
168                 <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
169                 <xslo:value-of select="$full_thesaurus_code"/>
170             </z:index>
171         </xslo:template>
172     </xsl:template>
173
174     <xsl:template name="handle-index-leader">
175         <xsl:if test="kohaidx:index_leader">
176             <xslo:template match="marc:leader">
177                 <xsl:apply-templates select="kohaidx:index_leader" mode="secondary"/>
178             </xslo:template>
179         </xsl:if>
180     </xsl:template>
181
182     <xsl:template match="kohaidx:index_leader" mode="secondary">
183         <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
184         <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
185         <xsl:variable name="indexes">
186             <xsl:call-template name="get-target-indexes"/>
187         </xsl:variable>
188         <z:index>
189             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
190             <xslo:value-of>
191                 <xsl:attribute name="select">
192                     <xsl:text>substring(., </xsl:text>
193                     <xsl:value-of select="$offset + 1" />
194                     <xsl:text>, </xsl:text>
195                     <xsl:value-of select="$length" />
196                     <xsl:text>)</xsl:text>
197                 </xsl:attribute>
198             </xslo:value-of>
199         </z:index>
200     </xsl:template>
201
202     <xsl:template name="handle-index-control-field">
203         <xsl:for-each select="//kohaidx:index_control_field[generate-id() = generate-id(key('index_control_field_tag', @tag)[1])]">
204             <xslo:template>
205                 <xsl:attribute name="match">
206                     <xsl:text>marc:controlfield[@tag='</xsl:text>
207                     <xsl:value-of select="@tag"/>
208                     <xsl:text>']</xsl:text>
209                 </xsl:attribute>
210                 <xsl:for-each select="key('index_control_field_tag', @tag)">
211                     <xsl:call-template name="handle-one-index-control-field"/>
212                 </xsl:for-each>
213             </xslo:template>
214         </xsl:for-each>
215     </xsl:template>
216
217     <xsl:template name="handle-one-index-control-field">
218         <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
219         <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
220         <xsl:variable name="indexes">
221             <xsl:call-template name="get-target-indexes"/>
222         </xsl:variable>
223         <z:index>
224             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
225             <xslo:value-of>
226                 <xsl:attribute name="select">
227                     <xsl:choose>
228                         <xsl:when test="@length">
229                             <xsl:text>substring(., </xsl:text>
230                             <xsl:value-of select="$offset + 1" />
231                             <xsl:text>, </xsl:text>
232                             <xsl:value-of select="$length"/>
233                             <xsl:text>)</xsl:text>
234                         </xsl:when>
235                         <xsl:otherwise>
236                             <xsl:text>.</xsl:text>
237                         </xsl:otherwise>
238                     </xsl:choose>
239                 </xsl:attribute>
240             </xslo:value-of>
241         </z:index>
242     </xsl:template>
243
244     <xsl:template name="handle-index-subfields">
245         <xsl:for-each select="//kohaidx:index_subfields[generate-id() = generate-id(key('index_subfields_tag', @tag)[1])]">
246             <xslo:template mode="index_subfields">
247                 <xsl:attribute name="match">
248                     <xsl:text>marc:datafield[@tag='</xsl:text>
249                     <xsl:value-of select="@tag"/>
250                     <xsl:text>']</xsl:text>
251                 </xsl:attribute>
252                 <xsl:for-each select="key('index_subfields_tag', @tag)">
253                     <xsl:call-template name="handle-one-index-subfields"/>
254                 </xsl:for-each>
255             </xslo:template>
256         </xsl:for-each>
257     </xsl:template>
258
259     <xsl:template name="handle-one-index-subfields">
260         <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
261         <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
262         <xsl:variable name="indexes">
263             <xsl:call-template name="get-target-indexes"/>
264         </xsl:variable>
265             <xslo:for-each select="marc:subfield">
266                 <xslo:if>
267                     <xsl:attribute name="test">
268                         <xsl:text>contains('</xsl:text>
269                         <xsl:value-of select="@subfields"/>
270                         <xsl:text>', @code)</xsl:text>
271                     </xsl:attribute>
272                     <z:index>
273                         <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
274                         <xslo:value-of>
275                             <xsl:attribute name="select">
276                                 <xsl:choose>
277                                     <xsl:when test="@length">
278                                         <xsl:text>substring(., </xsl:text>
279                                         <xsl:value-of select="$offset + 1" />
280                                         <xsl:text>, </xsl:text>
281                                         <xsl:value-of select="$length"/>
282                                         <xsl:text>)</xsl:text>
283                                     </xsl:when>
284                                     <xsl:otherwise>
285                                         <xsl:text>.</xsl:text>
286                                     </xsl:otherwise>
287                                 </xsl:choose>
288                             </xsl:attribute>
289                         </xslo:value-of>
290                     </z:index>
291                 </xslo:if>
292             </xslo:for-each>
293     </xsl:template>
294
295     <xsl:template name="handle-index-facets">
296       <xsl:for-each select="//kohaidx:facet[generate-id() = generate-id(key('index_facet_tag', @tag)[1])]">
297           <xslo:template mode="index_facets">
298             <xsl:attribute name="match">
299             <xsl:text>marc:datafield[@tag='</xsl:text>
300             <xsl:value-of select="@tag"/>
301             <xsl:text>']</xsl:text>
302             </xsl:attribute>
303             <xslo:if>
304               <xsl:attribute name="test">
305                 <xsl:text>not(@ind1='z')</xsl:text>
306               </xsl:attribute>
307               <xsl:for-each select="key('index_facet_tag', @tag)">
308                 <xsl:variable name="indexes">
309                   <xsl:call-template name="get-facets-target-indexes"/>
310                 </xsl:variable>
311                   <xsl:if test="not($indexes='')">
312                   <z:index>
313                   <xsl:attribute name="name">
314                     <xsl:value-of select="normalize-space($indexes)"/>
315                   </xsl:attribute>
316                   <xsl:call-template name="build-facet-value">
317                     <xsl:with-param name="subfields" select="@subfields"/>
318                   </xsl:call-template>
319                   </z:index>
320                 </xsl:if>
321               </xsl:for-each>
322             </xslo:if>
323           </xslo:template>
324       </xsl:for-each>
325     </xsl:template>
326
327     <xsl:template name="handle-index-data-field">
328         <xsl:for-each select="//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
329             <xslo:template mode="index_data_field">
330                 <xsl:attribute name="match">
331                     <xsl:text>marc:datafield[@tag='</xsl:text>
332                     <xsl:value-of select="@tag"/>
333                     <xsl:text>']</xsl:text>
334                 </xsl:attribute>
335                 <xsl:for-each select="key('index_data_field_tag', @tag)">
336                     <xsl:call-template name="handle-one-data-field"/>
337                 </xsl:for-each>
338             </xslo:template>
339         </xsl:for-each>
340     </xsl:template>
341
342     <xsl:template name="handle-index-heading-conditional">
343         <xsl:for-each select="//kohaidx:index_heading_conditional[generate-id() = generate-id(key('index_heading_conditional_tag', @tag)[1])]">
344             <xslo:template mode="index_heading_conditional">
345                 <xsl:attribute name="match">marc:datafield[@tag='<xsl:value-of select="@tag"/>']</xsl:attribute>
346                 <xslo:if>
347                     <xsl:attribute name="test"><xsl:value-of select="@test"/></xsl:attribute>
348                     <xsl:for-each select="key('index_heading_conditional_tag', @tag)">
349                         <xsl:call-template name="handle-one-index-heading"/>
350                     </xsl:for-each>
351                 </xslo:if>
352             </xslo:template>
353         </xsl:for-each>
354     </xsl:template>
355
356     <xsl:template name="handle-one-data-field">
357         <xsl:variable name="indexes">
358             <xsl:call-template name="get-target-indexes"/>
359         </xsl:variable>
360         <z:index>
361             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
362             <xslo:variable name="raw_heading">
363                 <xslo:for-each select="marc:subfield">
364                         <xslo:if test="position() > 1">
365                             <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
366                         </xslo:if>
367                         <xslo:value-of select="."/>
368                 </xslo:for-each>
369             </xslo:variable>
370             <xslo:value-of select="normalize-space($raw_heading)"/>
371         </z:index>
372     </xsl:template>
373
374     <xsl:template name="handle-index-heading">
375         <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
376             <xslo:template mode="index_heading">
377                 <xsl:attribute name="match">
378                     <xsl:text>marc:datafield[@tag='</xsl:text>
379                     <xsl:value-of select="@tag"/>
380                     <xsl:text>']</xsl:text>
381                 </xsl:attribute>
382                 <xsl:for-each select="key('index_heading_tag', @tag)">
383                     <xsl:call-template name="handle-one-index-heading"/>
384                 </xsl:for-each>
385             </xslo:template>
386         </xsl:for-each>
387     </xsl:template>
388
389     <xsl:template name="handle-one-index-heading">
390         <xsl:variable name="indexes">
391             <xsl:call-template name="get-target-indexes"/>
392         </xsl:variable>
393         <z:index>
394             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
395             <xslo:variable name="raw_heading">
396                 <xslo:for-each select="marc:subfield">
397                     <xslo:if>
398                         <xsl:attribute name="test">
399                             <xsl:text>contains('</xsl:text>
400                             <xsl:value-of select="@subfields"/>
401                             <xsl:text>', @code)</xsl:text>
402                         </xsl:attribute>
403                         <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
404                         <xslo:if test="position() > 1">
405                             <xslo:choose>
406                                 <xslo:when>
407                                     <xsl:attribute name="test">
408                                         <xsl:text>contains('</xsl:text>
409                                         <xsl:value-of select="@subdivisions"/>
410                                         <xsl:text>', @code)</xsl:text>
411                                     </xsl:attribute>
412                                     <xslo:text>--</xslo:text>
413                                 </xslo:when>
414                                 <xslo:otherwise>
415                                     <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
416                                 </xslo:otherwise>
417                             </xslo:choose>
418                         </xslo:if>
419                         <xslo:value-of select="."/>
420                     </xslo:if>
421                 </xslo:for-each>
422             </xslo:variable>
423             <xslo:value-of select="normalize-space($raw_heading)"/>
424         </z:index>
425     </xsl:template>
426
427     <xsl:template name="handle-index-match-heading">
428         <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
429             <xslo:template mode="index_match_heading">
430                 <xsl:attribute name="match">
431                     <xsl:text>marc:datafield[@tag='</xsl:text>
432                     <xsl:value-of select="@tag"/>
433                     <xsl:text>']</xsl:text>
434                 </xsl:attribute>
435                 <xsl:for-each select="key('index_match_heading_tag', @tag)">
436                     <xsl:call-template name="handle-one-index-match-heading"/>
437                 </xsl:for-each>
438             </xslo:template>
439         </xsl:for-each>
440     </xsl:template>
441
442     <xsl:template name="handle-one-index-match-heading">
443         <xsl:variable name="indexes">
444             <xsl:call-template name="get-target-indexes"/>
445         </xsl:variable>
446         <z:index>
447             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
448             <xslo:variable name="raw_heading">
449                 <xslo:for-each select="marc:subfield">
450                     <xslo:if>
451                         <xsl:attribute name="test">
452                             <xsl:text>contains('</xsl:text>
453                             <xsl:value-of select="@subfields"/>
454                             <xsl:text>', @code)</xsl:text>
455                         </xsl:attribute>
456                         <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
457                         <xslo:if test="position() > 1">
458                             <xslo:choose>
459                                 <xslo:when>
460                                     <xsl:attribute name="test">
461                                         <xsl:text>contains('</xsl:text>
462                                         <xsl:value-of select="@subdivisions"/>
463                                         <xsl:text>', @code)</xsl:text>
464                                     </xsl:attribute>
465                                     <xslo:choose>
466                                         <xslo:when>
467                                             <xsl:attribute name="test">
468                                                 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
469                                             </xsl:attribute>
470                                             <xslo:text> generalsubdiv </xslo:text>
471                                         </xslo:when>
472                                         <xslo:when>
473                                             <xsl:attribute name="test">
474                                                 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
475                                             </xsl:attribute>
476                                             <xslo:text> formsubdiv </xslo:text>
477                                         </xslo:when>
478                                         <xslo:when>
479                                             <xsl:attribute name="test">
480                                                 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
481                                             </xsl:attribute>
482                                             <xslo:text> chronologicalsubdiv </xslo:text>
483                                         </xslo:when>
484                                         <xslo:when>
485                                             <xsl:attribute name="test">
486                                                 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
487                                             </xsl:attribute>
488                                             <xslo:text> geographicsubdiv </xslo:text>
489                                         </xslo:when>
490                                     </xslo:choose>
491                                 </xslo:when>
492                                 <xslo:otherwise>
493                                     <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
494                                 </xslo:otherwise>
495                             </xslo:choose>
496                         </xslo:if>
497                         <xslo:call-template name="chopPunctuation">
498                             <xslo:with-param name="chopString">
499                                 <xslo:value-of select="."/>
500                             </xslo:with-param>
501                         </xslo:call-template>
502                     </xslo:if>
503                 </xslo:for-each>
504             </xslo:variable>
505             <xslo:value-of select="normalize-space($raw_heading)"/>
506         </z:index>
507     </xsl:template>
508
509     <xsl:template name="get-target-indexes">
510         <xsl:for-each select="kohaidx:target_index">
511             <xsl:value-of select="." /><xsl:text> </xsl:text>
512         </xsl:for-each>
513     </xsl:template>
514
515     <xsl:template name="get-facets-target-indexes">
516         <xsl:for-each select="kohaidx:target_index">
517             <xsl:value-of select="." /><xsl:text> </xsl:text>
518         </xsl:for-each>
519     </xsl:template>
520
521     <!-- traverse subfields string character-wise -->
522     <xsl:template name="build-facet-value">
523       <xsl:param name="subfields"/>
524       <xsl:if test="string-length($subfields) &gt; 0">
525         <xslo:value-of>
526           <xsl:attribute name="select">
527               <xsl:text>marc:subfield[@code='</xsl:text>
528               <xsl:value-of select="substring($subfields,1,1)"/>
529               <xsl:text>']</xsl:text>
530           </xsl:attribute>
531         </xslo:value-of>
532         <xsl:call-template name="build-facet-value-cont">
533           <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
534           <xsl:with-param name="subfields" select="substring($subfields,2)"/>
535         </xsl:call-template>
536       </xsl:if>
537     </xsl:template>
538     <!-- traverse the remainder of @subfields, with context information
539          i.e previous char. Introduces a separator character if needed -->
540     <xsl:template name="build-facet-value-cont">
541       <xsl:param name="prev"/>
542       <xsl:param name="subfields"/>
543       <xsl:if test="string-length($subfields) &gt; 0">
544         <xslo:if>
545             <xsl:attribute name="test">
546                 <xsl:text>marc:subfield[@code='</xsl:text>
547                 <xsl:value-of select="$prev"/>
548                 <xsl:text>'] and marc:subfield[@code='</xsl:text>
549                 <xsl:value-of select="substring($subfields,1,1)"/>
550                 <xsl:text>']</xsl:text>
551             </xsl:attribute>
552             <xslo:text>&lt;*&gt;</xslo:text>
553         </xslo:if>
554         <xslo:value-of>
555           <xsl:attribute name="select">
556               <xsl:text>marc:subfield[@code='</xsl:text>
557               <xsl:value-of select="substring($subfields,1,1)"/>
558               <xsl:text>']</xsl:text>
559           </xsl:attribute>
560         </xslo:value-of>
561         <xsl:call-template name="build-facet-value-cont">
562           <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
563           <xsl:with-param name="subfields" select="substring($subfields,2)"/>
564         </xsl:call-template>
565       </xsl:if>
566     </xsl:template>
567
568 </xsl:stylesheet>