Bug 14217: Add 'condition' attribute for DOM index definition
[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="//kohaidx: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:choose>
254                         <xsl:when test="@condition">
255                             <xslo:if>
256                                 <xsl:attribute name="test">
257                                     <xsl:value-of select="@condition"/>
258                                 </xsl:attribute>
259                                 <xsl:call-template name="handle-one-index-subfields" />
260                             </xslo:if>
261                         </xsl:when>
262                         <xsl:otherwise>
263                             <xsl:call-template name="handle-one-index-subfields" />
264                         </xsl:otherwise>
265                     </xsl:choose>
266                 </xsl:for-each>
267             </xslo:template>
268         </xsl:for-each>
269     </xsl:template>
270
271     <xsl:template name="handle-one-index-subfields">
272         <xsl:variable name="offset"><xsl:value-of select="@offset"/></xsl:variable>
273         <xsl:variable name="length"><xsl:value-of select="@length"/></xsl:variable>
274         <xsl:variable name="indexes">
275             <xsl:call-template name="get-target-indexes"/>
276         </xsl:variable>
277
278         <xslo:for-each select="marc:subfield">
279             <xslo:if>
280                 <xsl:attribute name="test">
281                     <xsl:text>contains('</xsl:text>
282                     <xsl:value-of select="@subfields"/>
283                     <xsl:text>', @code)</xsl:text>
284                 </xsl:attribute>
285                 <z:index>
286                     <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
287                     <xslo:value-of>
288                         <xsl:attribute name="select">
289                             <xsl:choose>
290                                 <xsl:when test="@length">
291                                     <xsl:text>substring(., </xsl:text>
292                                     <xsl:value-of select="$offset + 1" />
293                                     <xsl:text>, </xsl:text>
294                                     <xsl:value-of select="$length"/>
295                                     <xsl:text>)</xsl:text>
296                                 </xsl:when>
297                                 <xsl:otherwise>
298                                     <xsl:text>.</xsl:text>
299                                 </xsl:otherwise>
300                             </xsl:choose>
301                         </xsl:attribute>
302                     </xslo:value-of>
303                 </z:index>
304             </xslo:if>
305         </xslo:for-each>
306     </xsl:template>
307
308     <xsl:template name="handle-index-facets">
309       <xsl:for-each select="//kohaidx:facet[generate-id() = generate-id(key('index_facet_tag', @tag)[1])]">
310           <xslo:template mode="index_facets">
311             <xsl:attribute name="match">
312             <xsl:text>marc:datafield[@tag='</xsl:text>
313             <xsl:value-of select="@tag"/>
314             <xsl:text>']</xsl:text>
315             </xsl:attribute>
316             <xslo:if>
317               <xsl:attribute name="test">
318                 <xsl:text>not(@ind1='z')</xsl:text>
319               </xsl:attribute>
320               <xsl:for-each select="key('index_facet_tag', @tag)">
321                 <xsl:variable name="indexes">
322                   <xsl:call-template name="get-facets-target-indexes"/>
323                 </xsl:variable>
324                   <xsl:if test="not($indexes='')">
325                   <z:index>
326                   <xsl:attribute name="name">
327                     <xsl:value-of select="normalize-space($indexes)"/>
328                   </xsl:attribute>
329                   <xsl:call-template name="build-facet-value">
330                     <xsl:with-param name="subfields" select="@subfields"/>
331                   </xsl:call-template>
332                   </z:index>
333                 </xsl:if>
334               </xsl:for-each>
335             </xslo:if>
336           </xslo:template>
337       </xsl:for-each>
338     </xsl:template>
339
340     <xsl:template name="handle-index-data-field">
341         <xsl:for-each select="//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
342             <xslo:template mode="index_data_field">
343                 <xsl:attribute name="match">
344                     <xsl:text>marc:datafield[@tag='</xsl:text>
345                     <xsl:value-of select="@tag"/>
346                     <xsl:text>']</xsl:text>
347                 </xsl:attribute>
348                 <xsl:for-each select="key('index_data_field_tag', @tag)">
349                     <xsl:call-template name="handle-one-data-field"/>
350                 </xsl:for-each>
351             </xslo:template>
352         </xsl:for-each>
353     </xsl:template>
354
355     <xsl:template name="handle-index-heading-conditional">
356         <xsl:for-each select="//kohaidx:index_heading_conditional[generate-id() = generate-id(key('index_heading_conditional_tag', @tag)[1])]">
357             <xslo:template mode="index_heading_conditional">
358                 <xsl:attribute name="match">marc:datafield[@tag='<xsl:value-of select="@tag"/>']</xsl:attribute>
359                 <xslo:if>
360                     <xsl:attribute name="test"><xsl:value-of select="@test"/></xsl:attribute>
361                     <xsl:for-each select="key('index_heading_conditional_tag', @tag)">
362                         <xsl:call-template name="handle-one-index-heading"/>
363                     </xsl:for-each>
364                 </xslo:if>
365             </xslo:template>
366         </xsl:for-each>
367     </xsl:template>
368
369     <xsl:template name="handle-one-data-field">
370         <xsl:variable name="indexes">
371             <xsl:call-template name="get-target-indexes"/>
372         </xsl:variable>
373         <z:index>
374             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
375             <xslo:variable name="raw_heading">
376                 <xslo:for-each select="marc:subfield">
377                         <xslo:if test="position() > 1">
378                             <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
379                         </xslo:if>
380                         <xslo:value-of select="."/>
381                 </xslo:for-each>
382             </xslo:variable>
383             <xslo:value-of select="normalize-space($raw_heading)"/>
384         </z:index>
385     </xsl:template>
386
387     <xsl:template name="handle-index-heading">
388         <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
389             <xslo:template mode="index_heading">
390                 <xsl:attribute name="match">
391                     <xsl:text>marc:datafield[@tag='</xsl:text>
392                     <xsl:value-of select="@tag"/>
393                     <xsl:text>']</xsl:text>
394                 </xsl:attribute>
395                 <xsl:for-each select="key('index_heading_tag', @tag)">
396                     <xsl:call-template name="handle-one-index-heading"/>
397                 </xsl:for-each>
398             </xslo:template>
399         </xsl:for-each>
400     </xsl:template>
401
402     <xsl:template name="handle-one-index-heading">
403         <xsl:variable name="indexes">
404             <xsl:call-template name="get-target-indexes"/>
405         </xsl:variable>
406         <z:index>
407             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
408             <xslo:variable name="raw_heading">
409                 <xslo:for-each select="marc:subfield">
410                     <xslo:if>
411                         <xsl:attribute name="test">
412                             <xsl:text>contains('</xsl:text>
413                             <xsl:value-of select="@subfields"/>
414                             <xsl:text>', @code)</xsl:text>
415                         </xsl:attribute>
416                         <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
417                         <xslo:if test="position() > 1">
418                             <xslo:choose>
419                                 <xslo:when>
420                                     <xsl:attribute name="test">
421                                         <xsl:text>contains('</xsl:text>
422                                         <xsl:value-of select="@subdivisions"/>
423                                         <xsl:text>', @code)</xsl:text>
424                                     </xsl:attribute>
425                                     <xslo:text>--</xslo:text>
426                                 </xslo:when>
427                                 <xslo:otherwise>
428                                     <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
429                                 </xslo:otherwise>
430                             </xslo:choose>
431                         </xslo:if>
432                         <xslo:value-of select="."/>
433                     </xslo:if>
434                 </xslo:for-each>
435             </xslo:variable>
436             <xslo:value-of select="normalize-space($raw_heading)"/>
437         </z:index>
438     </xsl:template>
439
440     <xsl:template name="handle-index-match-heading">
441         <xsl:for-each select="//kohaidx:index_match_heading[generate-id() = generate-id(key('index_match_heading_tag', @tag)[1])]">
442             <xslo:template mode="index_match_heading">
443                 <xsl:attribute name="match">
444                     <xsl:text>marc:datafield[@tag='</xsl:text>
445                     <xsl:value-of select="@tag"/>
446                     <xsl:text>']</xsl:text>
447                 </xsl:attribute>
448                 <xsl:for-each select="key('index_match_heading_tag', @tag)">
449                     <xsl:call-template name="handle-one-index-match-heading"/>
450                 </xsl:for-each>
451             </xslo:template>
452         </xsl:for-each>
453     </xsl:template>
454
455     <xsl:template name="handle-one-index-match-heading">
456         <xsl:variable name="indexes">
457             <xsl:call-template name="get-target-indexes"/>
458         </xsl:variable>
459         <z:index>
460             <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
461             <xslo:variable name="raw_heading">
462                 <xslo:for-each select="marc:subfield">
463                     <xslo:if>
464                         <xsl:attribute name="test">
465                             <xsl:text>contains('</xsl:text>
466                             <xsl:value-of select="@subfields"/>
467                             <xsl:text>', @code)</xsl:text>
468                         </xsl:attribute>
469                         <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
470                         <xslo:if test="position() > 1">
471                             <xslo:choose>
472                                 <xslo:when>
473                                     <xsl:attribute name="test">
474                                         <xsl:text>contains('</xsl:text>
475                                         <xsl:value-of select="@subdivisions"/>
476                                         <xsl:text>', @code)</xsl:text>
477                                     </xsl:attribute>
478                                     <xslo:choose>
479                                         <xslo:when>
480                                             <xsl:attribute name="test">
481                                                 <xsl:text>@code = $general_subdivision_subfield</xsl:text>
482                                             </xsl:attribute>
483                                             <xslo:text> generalsubdiv </xslo:text>
484                                         </xslo:when>
485                                         <xslo:when>
486                                             <xsl:attribute name="test">
487                                                 <xsl:text>@code = $form_subdivision_subfield</xsl:text>
488                                             </xsl:attribute>
489                                             <xslo:text> formsubdiv </xslo:text>
490                                         </xslo:when>
491                                         <xslo:when>
492                                             <xsl:attribute name="test">
493                                                 <xsl:text>@code = $chronological_subdivision_subfield</xsl:text>
494                                             </xsl:attribute>
495                                             <xslo:text> chronologicalsubdiv </xslo:text>
496                                         </xslo:when>
497                                         <xslo:when>
498                                             <xsl:attribute name="test">
499                                                 <xsl:text>@code = $geographic_subdivision_subfield</xsl:text>
500                                             </xsl:attribute>
501                                             <xslo:text> geographicsubdiv </xslo:text>
502                                         </xslo:when>
503                                     </xslo:choose>
504                                 </xslo:when>
505                                 <xslo:otherwise>
506                                     <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
507                                 </xslo:otherwise>
508                             </xslo:choose>
509                         </xslo:if>
510                         <xslo:call-template name="chopPunctuation">
511                             <xslo:with-param name="chopString">
512                                 <xslo:value-of select="."/>
513                             </xslo:with-param>
514                         </xslo:call-template>
515                     </xslo:if>
516                 </xslo:for-each>
517             </xslo:variable>
518             <xslo:value-of select="normalize-space($raw_heading)"/>
519         </z:index>
520     </xsl:template>
521
522     <xsl:template name="get-target-indexes">
523         <xsl:for-each select="kohaidx:target_index">
524             <xsl:value-of select="." /><xsl:text> </xsl:text>
525         </xsl:for-each>
526     </xsl:template>
527
528     <xsl:template name="get-facets-target-indexes">
529         <xsl:for-each select="kohaidx:target_index">
530             <xsl:value-of select="." /><xsl:text> </xsl:text>
531         </xsl:for-each>
532     </xsl:template>
533
534     <!-- traverse subfields string character-wise -->
535     <xsl:template name="build-facet-value">
536       <xsl:param name="subfields"/>
537       <xsl:if test="string-length($subfields) &gt; 0">
538         <xslo:value-of>
539           <xsl:attribute name="select">
540               <xsl:text>marc:subfield[@code='</xsl:text>
541               <xsl:value-of select="substring($subfields,1,1)"/>
542               <xsl:text>']</xsl:text>
543           </xsl:attribute>
544         </xslo:value-of>
545         <xsl:call-template name="build-facet-value-cont">
546           <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
547           <xsl:with-param name="subfields" select="substring($subfields,2)"/>
548         </xsl:call-template>
549       </xsl:if>
550     </xsl:template>
551     <!-- traverse the remainder of @subfields, with context information
552          i.e previous char. Introduces a separator character if needed -->
553     <xsl:template name="build-facet-value-cont">
554       <xsl:param name="prev"/>
555       <xsl:param name="subfields"/>
556       <xsl:if test="string-length($subfields) &gt; 0">
557         <xslo:if>
558             <xsl:attribute name="test">
559                 <xsl:text>marc:subfield[@code='</xsl:text>
560                 <xsl:value-of select="$prev"/>
561                 <xsl:text>'] and marc:subfield[@code='</xsl:text>
562                 <xsl:value-of select="substring($subfields,1,1)"/>
563                 <xsl:text>']</xsl:text>
564             </xsl:attribute>
565             <xslo:text>&lt;*&gt;</xslo:text>
566         </xslo:if>
567         <xslo:value-of>
568           <xsl:attribute name="select">
569               <xsl:text>marc:subfield[@code='</xsl:text>
570               <xsl:value-of select="substring($subfields,1,1)"/>
571               <xsl:text>']</xsl:text>
572           </xsl:attribute>
573         </xslo:value-of>
574         <xsl:call-template name="build-facet-value-cont">
575           <xsl:with-param name="prev" select="substring($subfields,1,1)"/>
576           <xsl:with-param name="subfields" select="substring($subfields,2)"/>
577         </xsl:call-template>
578       </xsl:if>
579     </xsl:template>
580
581 </xsl:stylesheet>