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