DOM authority indexing fixes (partial fix for 1906)
[koha.git] / etc / zebradb / marc_defs / marc21 / authorities / authority-zebra-indexdefs.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xslo:stylesheet xmlns:xslo="http://www.w3.org/1999/XSL/Transform" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:z="http://indexdata.com/zebra-2.0" xmlns:kohaidx="http://www.koha.org/schemas/index-defs" version="1.0">
3   <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
4   <xslo:template match="text()"/>
5   <xslo:template match="text()" mode="index_subfields"/>
6   <xslo:template match="text()" mode="index_heading"/>
7   <xslo:template match="text()" mode="index_match_heading"/>
8   <xslo:template match="text()" mode="index_subject_thesaurus"/>
9   <xslo:template match="/">
10     <xslo:if test="marc:collection">
11       <collection>
12         <xslo:apply-templates select="marc:collection/marc:record"/>
13       </collection>
14     </xslo:if>
15     <xslo:if test="marc:record">
16       <xslo:apply-templates select="marc:record"/>
17     </xslo:if>
18   </xslo:template>
19   <xslo:template match="marc:record">
20     <xslo:variable name="controlField001" select="normalize-space(marc:controlfield[@tag='001'])"/>
21     <z:record type="update">
22       <xslo:attribute name="z:id">
23         <xslo:value-of select="$controlField001"/>
24       </xslo:attribute>
25       <xslo:apply-templates/>
26       <xslo:apply-templates mode="index_subfields"/>
27       <xslo:apply-templates mode="index_heading"/>
28       <xslo:apply-templates mode="index_match_heading"/>
29       <xslo:apply-templates mode="index_subject_thesaurus"/>
30     </z:record>
31   </xslo:template>
32   <xslo:template match="marc:leader">
33     <z:index name="Record-status:w">
34       <xslo:value-of select="substring(., 6, 1)"/>
35     </z:index>
36     <z:index name="Encoding-level:w">
37       <xslo:value-of select="substring(., 18, 1)"/>
38     </z:index>
39   </xslo:template>
40   <xslo:template match="marc:controlfield[@tag='001']">
41     <z:index name="Local-Number:w">
42       <xslo:value-of select="."/>
43     </z:index>
44   </xslo:template>
45   <xslo:template match="marc:controlfield[@tag='008']">
46     <z:index name="Kind-of-record:w">
47       <xslo:value-of select="substring(., 10, 1)"/>
48     </z:index>
49     <z:index name="Descriptive-cataloging-rules:w">
50       <xslo:value-of select="substring(., 11, 1)"/>
51     </z:index>
52     <z:index name="Heading-use-main-or-added-entry:w">
53       <xslo:value-of select="substring(., 15, 1)"/>
54     </z:index>
55     <z:index name="Heading-use-subject-added-entry:w">
56       <xslo:value-of select="substring(., 16, 1)"/>
57     </z:index>
58     <z:index name="Heading-use-series-added-entry:w">
59       <xslo:value-of select="substring(., 17, 1)"/>
60     </z:index>
61   </xslo:template>
62   <xslo:template mode="index_subfields" match="marc:datafield[@tag='100']">
63     <xslo:for-each select="marc:subfield">
64       <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)">
65         <z:index name="Personal-name:w Personal-name:p Personal-name:s">
66           <xslo:value-of select="."/>
67         </z:index>
68       </xslo:if>
69     </xslo:for-each>
70   </xslo:template>
71   <xslo:template mode="index_subfields" match="marc:datafield[@tag='110']">
72     <xslo:for-each select="marc:subfield">
73       <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)">
74         <z:index name="Corporate-name:w Corporate-name:p">
75           <xslo:value-of select="."/>
76         </z:index>
77       </xslo:if>
78     </xslo:for-each>
79   </xslo:template>
80   <xslo:template mode="index_subfields" match="marc:datafield[@tag='111']">
81     <xslo:for-each select="marc:subfield">
82       <xslo:if test="contains('acdefghjklnpqstvxyz', @code)">
83         <z:index name="Meeting-name:w Meeting-name:p">
84           <xslo:value-of select="."/>
85         </z:index>
86       </xslo:if>
87     </xslo:for-each>
88   </xslo:template>
89   <xslo:template mode="index_subfields" match="marc:datafield[@tag='130']">
90     <xslo:for-each select="marc:subfield">
91       <xslo:if test="contains('adfghklmnoprstvxyz', @code)">
92         <z:index name="Title-uniform:w Title-uniform:p">
93           <xslo:value-of select="."/>
94         </z:index>
95       </xslo:if>
96     </xslo:for-each>
97   </xslo:template>
98   <xslo:template mode="index_subfields" match="marc:datafield[@tag='148']">
99     <xslo:for-each select="marc:subfield">
100       <xslo:if test="contains('avxyz', @code)">
101         <z:index name="Chronological-term:w Chronological-term:p">
102           <xslo:value-of select="."/>
103         </z:index>
104       </xslo:if>
105     </xslo:for-each>
106   </xslo:template>
107   <xslo:template mode="index_subfields" match="marc:datafield[@tag='150']">
108     <xslo:for-each select="marc:subfield">
109       <xslo:if test="contains('abvxyz', @code)">
110         <z:index name="Subject-topical:w Subject-topical:p">
111           <xslo:value-of select="."/>
112         </z:index>
113       </xslo:if>
114     </xslo:for-each>
115   </xslo:template>
116   <xslo:template mode="index_subfields" match="marc:datafield[@tag='151']">
117     <xslo:for-each select="marc:subfield">
118       <xslo:if test="contains('avxyz', @code)">
119         <z:index name="Name-geographic:w Name-geographic:p">
120           <xslo:value-of select="."/>
121         </z:index>
122       </xslo:if>
123     </xslo:for-each>
124   </xslo:template>
125   <xslo:template mode="index_subfields" match="marc:datafield[@tag='155']">
126     <xslo:for-each select="marc:subfield">
127       <xslo:if test="contains('avxyz', @code)">
128         <z:index name="Term-genre-form:w Term-genre-form:p">
129           <xslo:value-of select="."/>
130         </z:index>
131       </xslo:if>
132     </xslo:for-each>
133   </xslo:template>
134   <xslo:template mode="index_subfields" match="marc:datafield[@tag='942']">
135     <xslo:for-each select="marc:subfield">
136       <xslo:if test="contains('a', @code)">
137         <z:index name="authtype:w">
138           <xslo:value-of select="."/>
139         </z:index>
140       </xslo:if>
141     </xslo:for-each>
142   </xslo:template>
143   <xslo:template mode="index_heading" match="marc:datafield[@tag='100']">
144     <z:index name="Personal-name-heading:w Personal-name-heading:p Personal-name-heading:s Heading:w Heading:p Heading:s">
145       <xslo:variable name="raw_heading">
146         <xslo:for-each select="marc:subfield">
147           <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Personal-name-heading:w Personal-name-heading:p Personal-name-heading:s Heading:w Heading:p Heading:s">
148             <xslo:if test="position() &gt; 1">
149               <xslo:choose>
150                 <xslo:when test="contains('vxyz', @code)">
151                   <xslo:text>--</xslo:text>
152                 </xslo:when>
153                 <xslo:otherwise>
154                   <xslo:value-of select="substring(' ', 1, 1)"/>
155                 </xslo:otherwise>
156               </xslo:choose>
157             </xslo:if>
158             <xslo:value-of select="."/>
159           </xslo:if>
160         </xslo:for-each>
161       </xslo:variable>
162       <xslo:value-of select="normalize-space($raw_heading)"/>
163     </z:index>
164   </xslo:template>
165   <xslo:template mode="index_heading" match="marc:datafield[@tag='400']">
166     <z:index name="Personal-name-see-from:w Personal-name-see-from:p Personal-name-see-from:s See-from:w See-from:p See-from:s">
167       <xslo:variable name="raw_heading">
168         <xslo:for-each select="marc:subfield">
169           <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Personal-name-see-from:w Personal-name-see-from:p Personal-name-see-from:s See-from:w See-from:p See-from:s">
170             <xslo:if test="position() &gt; 1">
171               <xslo:choose>
172                 <xslo:when test="contains('vxyz', @code)">
173                   <xslo:text>--</xslo:text>
174                 </xslo:when>
175                 <xslo:otherwise>
176                   <xslo:value-of select="substring(' ', 1, 1)"/>
177                 </xslo:otherwise>
178               </xslo:choose>
179             </xslo:if>
180             <xslo:value-of select="."/>
181           </xslo:if>
182         </xslo:for-each>
183       </xslo:variable>
184       <xslo:value-of select="normalize-space($raw_heading)"/>
185     </z:index>
186   </xslo:template>
187   <xslo:template mode="index_heading" match="marc:datafield[@tag='500']">
188     <z:index name="Personal-name-see-also-from:w Personal-name-see-also-from:p Personal-name-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
189       <xslo:variable name="raw_heading">
190         <xslo:for-each select="marc:subfield">
191           <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Personal-name-see-also-from:w Personal-name-see-also-from:p Personal-name-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
192             <xslo:if test="position() &gt; 1">
193               <xslo:choose>
194                 <xslo:when test="contains('vxyz', @code)">
195                   <xslo:text>--</xslo:text>
196                 </xslo:when>
197                 <xslo:otherwise>
198                   <xslo:value-of select="substring(' ', 1, 1)"/>
199                 </xslo:otherwise>
200               </xslo:choose>
201             </xslo:if>
202             <xslo:value-of select="."/>
203           </xslo:if>
204         </xslo:for-each>
205       </xslo:variable>
206       <xslo:value-of select="normalize-space($raw_heading)"/>
207     </z:index>
208   </xslo:template>
209   <xslo:template mode="index_heading" match="marc:datafield[@tag='110']">
210     <z:index name="Corporate-name-heading:w Corporate-name-heading:p Corporate-name-heading:s Heading:w Heading:p Heading:s">
211       <xslo:variable name="raw_heading">
212         <xslo:for-each select="marc:subfield">
213           <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Corporate-name-heading:w Corporate-name-heading:p Corporate-name-heading:s Heading:w Heading:p Heading:s">
214             <xslo:if test="position() &gt; 1">
215               <xslo:choose>
216                 <xslo:when test="contains('vxyz', @code)">
217                   <xslo:text>--</xslo:text>
218                 </xslo:when>
219                 <xslo:otherwise>
220                   <xslo:value-of select="substring(' ', 1, 1)"/>
221                 </xslo:otherwise>
222               </xslo:choose>
223             </xslo:if>
224             <xslo:value-of select="."/>
225           </xslo:if>
226         </xslo:for-each>
227       </xslo:variable>
228       <xslo:value-of select="normalize-space($raw_heading)"/>
229     </z:index>
230   </xslo:template>
231   <xslo:template mode="index_heading" match="marc:datafield[@tag='410']">
232     <z:index name="Corporate-name-see-from:w Corporate-name-see-from:p Corporate-name-see-from:s See-from:w See-from:p See-from:s">
233       <xslo:variable name="raw_heading">
234         <xslo:for-each select="marc:subfield">
235           <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Corporate-name-see-from:w Corporate-name-see-from:p Corporate-name-see-from:s See-from:w See-from:p See-from:s">
236             <xslo:if test="position() &gt; 1">
237               <xslo:choose>
238                 <xslo:when test="contains('vxyz', @code)">
239                   <xslo:text>--</xslo:text>
240                 </xslo:when>
241                 <xslo:otherwise>
242                   <xslo:value-of select="substring(' ', 1, 1)"/>
243                 </xslo:otherwise>
244               </xslo:choose>
245             </xslo:if>
246             <xslo:value-of select="."/>
247           </xslo:if>
248         </xslo:for-each>
249       </xslo:variable>
250       <xslo:value-of select="normalize-space($raw_heading)"/>
251     </z:index>
252   </xslo:template>
253   <xslo:template mode="index_heading" match="marc:datafield[@tag='510']">
254     <z:index name="Corporate-name-see-also-from:w Corporate-name-see-also-from:p Corporate-name-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
255       <xslo:variable name="raw_heading">
256         <xslo:for-each select="marc:subfield">
257           <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Corporate-name-see-also-from:w Corporate-name-see-also-from:p Corporate-name-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
258             <xslo:if test="position() &gt; 1">
259               <xslo:choose>
260                 <xslo:when test="contains('vxyz', @code)">
261                   <xslo:text>--</xslo:text>
262                 </xslo:when>
263                 <xslo:otherwise>
264                   <xslo:value-of select="substring(' ', 1, 1)"/>
265                 </xslo:otherwise>
266               </xslo:choose>
267             </xslo:if>
268             <xslo:value-of select="."/>
269           </xslo:if>
270         </xslo:for-each>
271       </xslo:variable>
272       <xslo:value-of select="normalize-space($raw_heading)"/>
273     </z:index>
274   </xslo:template>
275   <xslo:template mode="index_heading" match="marc:datafield[@tag='111']">
276     <z:index name="Meeting-name-heading:w Meeting-name-heading:p Meeting-name-heading:s Heading:w Heading:p Heading:s">
277       <xslo:variable name="raw_heading">
278         <xslo:for-each select="marc:subfield">
279           <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Meeting-name-heading:w Meeting-name-heading:p Meeting-name-heading:s Heading:w Heading:p Heading:s">
280             <xslo:if test="position() &gt; 1">
281               <xslo:choose>
282                 <xslo:when test="contains('vxyz', @code)">
283                   <xslo:text>--</xslo:text>
284                 </xslo:when>
285                 <xslo:otherwise>
286                   <xslo:value-of select="substring(' ', 1, 1)"/>
287                 </xslo:otherwise>
288               </xslo:choose>
289             </xslo:if>
290             <xslo:value-of select="."/>
291           </xslo:if>
292         </xslo:for-each>
293       </xslo:variable>
294       <xslo:value-of select="normalize-space($raw_heading)"/>
295     </z:index>
296   </xslo:template>
297   <xslo:template mode="index_heading" match="marc:datafield[@tag='411']">
298     <z:index name="Meeting-name-see-from:w Meeting-name-see-from:p Meeting-name-see-from:s See-from:w See-from:p See-from:s">
299       <xslo:variable name="raw_heading">
300         <xslo:for-each select="marc:subfield">
301           <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Meeting-name-see-from:w Meeting-name-see-from:p Meeting-name-see-from:s See-from:w See-from:p See-from:s">
302             <xslo:if test="position() &gt; 1">
303               <xslo:choose>
304                 <xslo:when test="contains('vxyz', @code)">
305                   <xslo:text>--</xslo:text>
306                 </xslo:when>
307                 <xslo:otherwise>
308                   <xslo:value-of select="substring(' ', 1, 1)"/>
309                 </xslo:otherwise>
310               </xslo:choose>
311             </xslo:if>
312             <xslo:value-of select="."/>
313           </xslo:if>
314         </xslo:for-each>
315       </xslo:variable>
316       <xslo:value-of select="normalize-space($raw_heading)"/>
317     </z:index>
318   </xslo:template>
319   <xslo:template mode="index_heading" match="marc:datafield[@tag='511']">
320     <z:index name="Meeting-name-see-also-from:w Meeting-name-see-also-from:p Meeting-name-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
321       <xslo:variable name="raw_heading">
322         <xslo:for-each select="marc:subfield">
323           <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Meeting-name-see-also-from:w Meeting-name-see-also-from:p Meeting-name-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
324             <xslo:if test="position() &gt; 1">
325               <xslo:choose>
326                 <xslo:when test="contains('vxyz', @code)">
327                   <xslo:text>--</xslo:text>
328                 </xslo:when>
329                 <xslo:otherwise>
330                   <xslo:value-of select="substring(' ', 1, 1)"/>
331                 </xslo:otherwise>
332               </xslo:choose>
333             </xslo:if>
334             <xslo:value-of select="."/>
335           </xslo:if>
336         </xslo:for-each>
337       </xslo:variable>
338       <xslo:value-of select="normalize-space($raw_heading)"/>
339     </z:index>
340   </xslo:template>
341   <xslo:template mode="index_heading" match="marc:datafield[@tag='130']">
342     <z:index name="Title-uniform-heading:w Title-uniform-heading:p Title-uniform-heading:s Heading:w Heading:p Heading:s">
343       <xslo:variable name="raw_heading">
344         <xslo:for-each select="marc:subfield">
345           <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Title-uniform-heading:w Title-uniform-heading:p Title-uniform-heading:s Heading:w Heading:p Heading:s">
346             <xslo:if test="position() &gt; 1">
347               <xslo:choose>
348                 <xslo:when test="contains('vxyz', @code)">
349                   <xslo:text>--</xslo:text>
350                 </xslo:when>
351                 <xslo:otherwise>
352                   <xslo:value-of select="substring(' ', 1, 1)"/>
353                 </xslo:otherwise>
354               </xslo:choose>
355             </xslo:if>
356             <xslo:value-of select="."/>
357           </xslo:if>
358         </xslo:for-each>
359       </xslo:variable>
360       <xslo:value-of select="normalize-space($raw_heading)"/>
361     </z:index>
362   </xslo:template>
363   <xslo:template mode="index_heading" match="marc:datafield[@tag='430']">
364     <z:index name="Title-uniform-see-from:w Title-uniform-see-from:p Title-uniform-see-from:s See-from:w See-from:p See-from:s">
365       <xslo:variable name="raw_heading">
366         <xslo:for-each select="marc:subfield">
367           <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Title-uniform-see-from:w Title-uniform-see-from:p Title-uniform-see-from:s See-from:w See-from:p See-from:s">
368             <xslo:if test="position() &gt; 1">
369               <xslo:choose>
370                 <xslo:when test="contains('vxyz', @code)">
371                   <xslo:text>--</xslo:text>
372                 </xslo:when>
373                 <xslo:otherwise>
374                   <xslo:value-of select="substring(' ', 1, 1)"/>
375                 </xslo:otherwise>
376               </xslo:choose>
377             </xslo:if>
378             <xslo:value-of select="."/>
379           </xslo:if>
380         </xslo:for-each>
381       </xslo:variable>
382       <xslo:value-of select="normalize-space($raw_heading)"/>
383     </z:index>
384   </xslo:template>
385   <xslo:template mode="index_heading" match="marc:datafield[@tag='530']">
386     <z:index name="Title-uniform-see-also-from:w Title-uniform-see-also-from:p Title-uniform-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
387       <xslo:variable name="raw_heading">
388         <xslo:for-each select="marc:subfield">
389           <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Title-uniform-see-also-from:w Title-uniform-see-also-from:p Title-uniform-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
390             <xslo:if test="position() &gt; 1">
391               <xslo:choose>
392                 <xslo:when test="contains('vxyz', @code)">
393                   <xslo:text>--</xslo:text>
394                 </xslo:when>
395                 <xslo:otherwise>
396                   <xslo:value-of select="substring(' ', 1, 1)"/>
397                 </xslo:otherwise>
398               </xslo:choose>
399             </xslo:if>
400             <xslo:value-of select="."/>
401           </xslo:if>
402         </xslo:for-each>
403       </xslo:variable>
404       <xslo:value-of select="normalize-space($raw_heading)"/>
405     </z:index>
406   </xslo:template>
407   <xslo:template mode="index_heading" match="marc:datafield[@tag='148']">
408     <z:index name="Chronological-term-heading:w Chronological-term-heading:p Chronological-term-heading:s Heading:w Heading:p Heading:s">
409       <xslo:variable name="raw_heading">
410         <xslo:for-each select="marc:subfield">
411           <xslo:if test="contains('avxyz', @code)" name="Chronological-term-heading:w Chronological-term-heading:p Chronological-term-heading:s Heading:w Heading:p Heading:s">
412             <xslo:if test="position() &gt; 1">
413               <xslo:choose>
414                 <xslo:when test="contains('vxyz', @code)">
415                   <xslo:text>--</xslo:text>
416                 </xslo:when>
417                 <xslo:otherwise>
418                   <xslo:value-of select="substring(' ', 1, 1)"/>
419                 </xslo:otherwise>
420               </xslo:choose>
421             </xslo:if>
422             <xslo:value-of select="."/>
423           </xslo:if>
424         </xslo:for-each>
425       </xslo:variable>
426       <xslo:value-of select="normalize-space($raw_heading)"/>
427     </z:index>
428   </xslo:template>
429   <xslo:template mode="index_heading" match="marc:datafield[@tag='448']">
430     <z:index name="Chronological-term-see-from:w Chronological-term-see-from:p Chronological-term-see-from:s See-from:w See-from:p See-from:s">
431       <xslo:variable name="raw_heading">
432         <xslo:for-each select="marc:subfield">
433           <xslo:if test="contains('avxyz', @code)" name="Chronological-term-see-from:w Chronological-term-see-from:p Chronological-term-see-from:s See-from:w See-from:p See-from:s">
434             <xslo:if test="position() &gt; 1">
435               <xslo:choose>
436                 <xslo:when test="contains('vxyz', @code)">
437                   <xslo:text>--</xslo:text>
438                 </xslo:when>
439                 <xslo:otherwise>
440                   <xslo:value-of select="substring(' ', 1, 1)"/>
441                 </xslo:otherwise>
442               </xslo:choose>
443             </xslo:if>
444             <xslo:value-of select="."/>
445           </xslo:if>
446         </xslo:for-each>
447       </xslo:variable>
448       <xslo:value-of select="normalize-space($raw_heading)"/>
449     </z:index>
450   </xslo:template>
451   <xslo:template mode="index_heading" match="marc:datafield[@tag='548']">
452     <z:index name="Chronological-term-see-also-from:w Chronological-term-see-also-from:p Chronological-term-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
453       <xslo:variable name="raw_heading">
454         <xslo:for-each select="marc:subfield">
455           <xslo:if test="contains('avxyz', @code)" name="Chronological-term-see-also-from:w Chronological-term-see-also-from:p Chronological-term-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
456             <xslo:if test="position() &gt; 1">
457               <xslo:choose>
458                 <xslo:when test="contains('vxyz', @code)">
459                   <xslo:text>--</xslo:text>
460                 </xslo:when>
461                 <xslo:otherwise>
462                   <xslo:value-of select="substring(' ', 1, 1)"/>
463                 </xslo:otherwise>
464               </xslo:choose>
465             </xslo:if>
466             <xslo:value-of select="."/>
467           </xslo:if>
468         </xslo:for-each>
469       </xslo:variable>
470       <xslo:value-of select="normalize-space($raw_heading)"/>
471     </z:index>
472   </xslo:template>
473   <xslo:template mode="index_heading" match="marc:datafield[@tag='150']">
474     <z:index name="Subject-topical-heading:w Subject-topical-heading:p Subject-topical-heading:s Heading:w Heading:p Heading:s">
475       <xslo:variable name="raw_heading">
476         <xslo:for-each select="marc:subfield">
477           <xslo:if test="contains('abvxyz', @code)" name="Subject-topical-heading:w Subject-topical-heading:p Subject-topical-heading:s Heading:w Heading:p Heading:s">
478             <xslo:if test="position() &gt; 1">
479               <xslo:choose>
480                 <xslo:when test="contains('vxyz', @code)">
481                   <xslo:text>--</xslo:text>
482                 </xslo:when>
483                 <xslo:otherwise>
484                   <xslo:value-of select="substring(' ', 1, 1)"/>
485                 </xslo:otherwise>
486               </xslo:choose>
487             </xslo:if>
488             <xslo:value-of select="."/>
489           </xslo:if>
490         </xslo:for-each>
491       </xslo:variable>
492       <xslo:value-of select="normalize-space($raw_heading)"/>
493     </z:index>
494   </xslo:template>
495   <xslo:template mode="index_heading" match="marc:datafield[@tag='450']">
496     <z:index name="Subject-topical-see-from:w Subject-topical-see-from:p Subject-topical-see-from:s See-from:w See-from:p See-from:s">
497       <xslo:variable name="raw_heading">
498         <xslo:for-each select="marc:subfield">
499           <xslo:if test="contains('abvxyz', @code)" name="Subject-topical-see-from:w Subject-topical-see-from:p Subject-topical-see-from:s See-from:w See-from:p See-from:s">
500             <xslo:if test="position() &gt; 1">
501               <xslo:choose>
502                 <xslo:when test="contains('vxyz', @code)">
503                   <xslo:text>--</xslo:text>
504                 </xslo:when>
505                 <xslo:otherwise>
506                   <xslo:value-of select="substring(' ', 1, 1)"/>
507                 </xslo:otherwise>
508               </xslo:choose>
509             </xslo:if>
510             <xslo:value-of select="."/>
511           </xslo:if>
512         </xslo:for-each>
513       </xslo:variable>
514       <xslo:value-of select="normalize-space($raw_heading)"/>
515     </z:index>
516   </xslo:template>
517   <xslo:template mode="index_heading" match="marc:datafield[@tag='550']">
518     <z:index name="Subject-topical-see-also-from:w Subject-topical-see-also-from:p Subject-topical-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
519       <xslo:variable name="raw_heading">
520         <xslo:for-each select="marc:subfield">
521           <xslo:if test="contains('abvxyz', @code)" name="Subject-topical-see-also-from:w Subject-topical-see-also-from:p Subject-topical-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
522             <xslo:if test="position() &gt; 1">
523               <xslo:choose>
524                 <xslo:when test="contains('vxyz', @code)">
525                   <xslo:text>--</xslo:text>
526                 </xslo:when>
527                 <xslo:otherwise>
528                   <xslo:value-of select="substring(' ', 1, 1)"/>
529                 </xslo:otherwise>
530               </xslo:choose>
531             </xslo:if>
532             <xslo:value-of select="."/>
533           </xslo:if>
534         </xslo:for-each>
535       </xslo:variable>
536       <xslo:value-of select="normalize-space($raw_heading)"/>
537     </z:index>
538   </xslo:template>
539   <xslo:template mode="index_heading" match="marc:datafield[@tag='151']">
540     <z:index name="Name-geographic-heading:w Name-geographic-heading:p Name-geographic-heading:s Heading:w Heading:p Heading:s">
541       <xslo:variable name="raw_heading">
542         <xslo:for-each select="marc:subfield">
543           <xslo:if test="contains('avxyz', @code)" name="Name-geographic-heading:w Name-geographic-heading:p Name-geographic-heading:s Heading:w Heading:p Heading:s">
544             <xslo:if test="position() &gt; 1">
545               <xslo:choose>
546                 <xslo:when test="contains('vxyz', @code)">
547                   <xslo:text>--</xslo:text>
548                 </xslo:when>
549                 <xslo:otherwise>
550                   <xslo:value-of select="substring(' ', 1, 1)"/>
551                 </xslo:otherwise>
552               </xslo:choose>
553             </xslo:if>
554             <xslo:value-of select="."/>
555           </xslo:if>
556         </xslo:for-each>
557       </xslo:variable>
558       <xslo:value-of select="normalize-space($raw_heading)"/>
559     </z:index>
560   </xslo:template>
561   <xslo:template mode="index_heading" match="marc:datafield[@tag='451']">
562     <z:index name="Name-geographic-see-from:w Name-geographic-see-from:p Name-geographic-see-from:s See-from:w See-from:p See-from:s">
563       <xslo:variable name="raw_heading">
564         <xslo:for-each select="marc:subfield">
565           <xslo:if test="contains('avxyz', @code)" name="Name-geographic-see-from:w Name-geographic-see-from:p Name-geographic-see-from:s See-from:w See-from:p See-from:s">
566             <xslo:if test="position() &gt; 1">
567               <xslo:choose>
568                 <xslo:when test="contains('vxyz', @code)">
569                   <xslo:text>--</xslo:text>
570                 </xslo:when>
571                 <xslo:otherwise>
572                   <xslo:value-of select="substring(' ', 1, 1)"/>
573                 </xslo:otherwise>
574               </xslo:choose>
575             </xslo:if>
576             <xslo:value-of select="."/>
577           </xslo:if>
578         </xslo:for-each>
579       </xslo:variable>
580       <xslo:value-of select="normalize-space($raw_heading)"/>
581     </z:index>
582   </xslo:template>
583   <xslo:template mode="index_heading" match="marc:datafield[@tag='551']">
584     <z:index name="Name-geographic-see-also-from:w Name-geographic-see-also-from:p Name-geographic-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
585       <xslo:variable name="raw_heading">
586         <xslo:for-each select="marc:subfield">
587           <xslo:if test="contains('avxyz', @code)" name="Name-geographic-see-also-from:w Name-geographic-see-also-from:p Name-geographic-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
588             <xslo:if test="position() &gt; 1">
589               <xslo:choose>
590                 <xslo:when test="contains('vxyz', @code)">
591                   <xslo:text>--</xslo:text>
592                 </xslo:when>
593                 <xslo:otherwise>
594                   <xslo:value-of select="substring(' ', 1, 1)"/>
595                 </xslo:otherwise>
596               </xslo:choose>
597             </xslo:if>
598             <xslo:value-of select="."/>
599           </xslo:if>
600         </xslo:for-each>
601       </xslo:variable>
602       <xslo:value-of select="normalize-space($raw_heading)"/>
603     </z:index>
604   </xslo:template>
605   <xslo:template mode="index_heading" match="marc:datafield[@tag='155']">
606     <z:index name="Term-genre-form-heading:w Term-genre-form-heading:p Term-genre-form-heading:s Heading:w Heading:p Heading:s">
607       <xslo:variable name="raw_heading">
608         <xslo:for-each select="marc:subfield">
609           <xslo:if test="contains('avxyz', @code)" name="Term-genre-form-heading:w Term-genre-form-heading:p Term-genre-form-heading:s Heading:w Heading:p Heading:s">
610             <xslo:if test="position() &gt; 1">
611               <xslo:choose>
612                 <xslo:when test="contains('vxyz', @code)">
613                   <xslo:text>--</xslo:text>
614                 </xslo:when>
615                 <xslo:otherwise>
616                   <xslo:value-of select="substring(' ', 1, 1)"/>
617                 </xslo:otherwise>
618               </xslo:choose>
619             </xslo:if>
620             <xslo:value-of select="."/>
621           </xslo:if>
622         </xslo:for-each>
623       </xslo:variable>
624       <xslo:value-of select="normalize-space($raw_heading)"/>
625     </z:index>
626   </xslo:template>
627   <xslo:template mode="index_heading" match="marc:datafield[@tag='455']">
628     <z:index name="Term-genre-form-see-from:w Term-genre-form-see-from:p Term-genre-form-see-from:s See-from:w See-from:p See-from:s">
629       <xslo:variable name="raw_heading">
630         <xslo:for-each select="marc:subfield">
631           <xslo:if test="contains('avxyz', @code)" name="Term-genre-form-see-from:w Term-genre-form-see-from:p Term-genre-form-see-from:s See-from:w See-from:p See-from:s">
632             <xslo:if test="position() &gt; 1">
633               <xslo:choose>
634                 <xslo:when test="contains('vxyz', @code)">
635                   <xslo:text>--</xslo:text>
636                 </xslo:when>
637                 <xslo:otherwise>
638                   <xslo:value-of select="substring(' ', 1, 1)"/>
639                 </xslo:otherwise>
640               </xslo:choose>
641             </xslo:if>
642             <xslo:value-of select="."/>
643           </xslo:if>
644         </xslo:for-each>
645       </xslo:variable>
646       <xslo:value-of select="normalize-space($raw_heading)"/>
647     </z:index>
648   </xslo:template>
649   <xslo:template mode="index_heading" match="marc:datafield[@tag='555']">
650     <z:index name="Term-genre-form-see-also-from:w Term-genre-form-see-also-from:p Term-genre-form-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
651       <xslo:variable name="raw_heading">
652         <xslo:for-each select="marc:subfield">
653           <xslo:if test="contains('avxyz', @code)" name="Term-genre-form-see-also-from:w Term-genre-form-see-also-from:p Term-genre-form-see-also-from:s See-also-from:w See-also-from:p See-also-from:s">
654             <xslo:if test="position() &gt; 1">
655               <xslo:choose>
656                 <xslo:when test="contains('vxyz', @code)">
657                   <xslo:text>--</xslo:text>
658                 </xslo:when>
659                 <xslo:otherwise>
660                   <xslo:value-of select="substring(' ', 1, 1)"/>
661                 </xslo:otherwise>
662               </xslo:choose>
663             </xslo:if>
664             <xslo:value-of select="."/>
665           </xslo:if>
666         </xslo:for-each>
667       </xslo:variable>
668       <xslo:value-of select="normalize-space($raw_heading)"/>
669     </z:index>
670   </xslo:template>
671   <xslo:template mode="index_heading" match="marc:datafield[@tag='180']">
672     <z:index name="General-subdivision:w General-subdivision:p General-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
673       <xslo:variable name="raw_heading">
674         <xslo:for-each select="marc:subfield">
675           <xslo:if test="contains('vxyz', @code)" name="General-subdivision:w General-subdivision:p General-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
676             <xslo:if test="position() &gt; 1">
677               <xslo:choose>
678                 <xslo:when test="contains('vxyz', @code)">
679                   <xslo:text>--</xslo:text>
680                 </xslo:when>
681                 <xslo:otherwise>
682                   <xslo:value-of select="substring(' ', 1, 1)"/>
683                 </xslo:otherwise>
684               </xslo:choose>
685             </xslo:if>
686             <xslo:value-of select="."/>
687           </xslo:if>
688         </xslo:for-each>
689       </xslo:variable>
690       <xslo:value-of select="normalize-space($raw_heading)"/>
691     </z:index>
692   </xslo:template>
693   <xslo:template mode="index_heading" match="marc:datafield[@tag='480']">
694     <z:index name="General-subdivision-see-from:w General-subdivision-see-from:p General-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
695       <xslo:variable name="raw_heading">
696         <xslo:for-each select="marc:subfield">
697           <xslo:if test="contains('vxyz', @code)" name="General-subdivision-see-from:w General-subdivision-see-from:p General-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
698             <xslo:if test="position() &gt; 1">
699               <xslo:choose>
700                 <xslo:when test="contains('vxyz', @code)">
701                   <xslo:text>--</xslo:text>
702                 </xslo:when>
703                 <xslo:otherwise>
704                   <xslo:value-of select="substring(' ', 1, 1)"/>
705                 </xslo:otherwise>
706               </xslo:choose>
707             </xslo:if>
708             <xslo:value-of select="."/>
709           </xslo:if>
710         </xslo:for-each>
711       </xslo:variable>
712       <xslo:value-of select="normalize-space($raw_heading)"/>
713     </z:index>
714   </xslo:template>
715   <xslo:template mode="index_heading" match="marc:datafield[@tag='580']">
716     <z:index name="General-subdivision-see-also-from:w General-subdivision-see-also-from:p General-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
717       <xslo:variable name="raw_heading">
718         <xslo:for-each select="marc:subfield">
719           <xslo:if test="contains('vxyz', @code)" name="General-subdivision-see-also-from:w General-subdivision-see-also-from:p General-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
720             <xslo:if test="position() &gt; 1">
721               <xslo:choose>
722                 <xslo:when test="contains('vxyz', @code)">
723                   <xslo:text>--</xslo:text>
724                 </xslo:when>
725                 <xslo:otherwise>
726                   <xslo:value-of select="substring(' ', 1, 1)"/>
727                 </xslo:otherwise>
728               </xslo:choose>
729             </xslo:if>
730             <xslo:value-of select="."/>
731           </xslo:if>
732         </xslo:for-each>
733       </xslo:variable>
734       <xslo:value-of select="normalize-space($raw_heading)"/>
735     </z:index>
736   </xslo:template>
737   <xslo:template mode="index_heading" match="marc:datafield[@tag='181']">
738     <z:index name="Geographic-subdivision:w Geographic-subdivision:p Geographic-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
739       <xslo:variable name="raw_heading">
740         <xslo:for-each select="marc:subfield">
741           <xslo:if test="contains('vxyz', @code)" name="Geographic-subdivision:w Geographic-subdivision:p Geographic-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
742             <xslo:if test="position() &gt; 1">
743               <xslo:choose>
744                 <xslo:when test="contains('vxyz', @code)">
745                   <xslo:text>--</xslo:text>
746                 </xslo:when>
747                 <xslo:otherwise>
748                   <xslo:value-of select="substring(' ', 1, 1)"/>
749                 </xslo:otherwise>
750               </xslo:choose>
751             </xslo:if>
752             <xslo:value-of select="."/>
753           </xslo:if>
754         </xslo:for-each>
755       </xslo:variable>
756       <xslo:value-of select="normalize-space($raw_heading)"/>
757     </z:index>
758   </xslo:template>
759   <xslo:template mode="index_heading" match="marc:datafield[@tag='481']">
760     <z:index name="Geographic-subdivision-see-from:w Geographic-subdivision-see-from:p Geographic-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
761       <xslo:variable name="raw_heading">
762         <xslo:for-each select="marc:subfield">
763           <xslo:if test="contains('vxyz', @code)" name="Geographic-subdivision-see-from:w Geographic-subdivision-see-from:p Geographic-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
764             <xslo:if test="position() &gt; 1">
765               <xslo:choose>
766                 <xslo:when test="contains('vxyz', @code)">
767                   <xslo:text>--</xslo:text>
768                 </xslo:when>
769                 <xslo:otherwise>
770                   <xslo:value-of select="substring(' ', 1, 1)"/>
771                 </xslo:otherwise>
772               </xslo:choose>
773             </xslo:if>
774             <xslo:value-of select="."/>
775           </xslo:if>
776         </xslo:for-each>
777       </xslo:variable>
778       <xslo:value-of select="normalize-space($raw_heading)"/>
779     </z:index>
780   </xslo:template>
781   <xslo:template mode="index_heading" match="marc:datafield[@tag='581']">
782     <z:index name="Geographic-subdivision-see-also-from:w Geographic-subdivision-see-also-from:p Geographic-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
783       <xslo:variable name="raw_heading">
784         <xslo:for-each select="marc:subfield">
785           <xslo:if test="contains('vxyz', @code)" name="Geographic-subdivision-see-also-from:w Geographic-subdivision-see-also-from:p Geographic-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
786             <xslo:if test="position() &gt; 1">
787               <xslo:choose>
788                 <xslo:when test="contains('vxyz', @code)">
789                   <xslo:text>--</xslo:text>
790                 </xslo:when>
791                 <xslo:otherwise>
792                   <xslo:value-of select="substring(' ', 1, 1)"/>
793                 </xslo:otherwise>
794               </xslo:choose>
795             </xslo:if>
796             <xslo:value-of select="."/>
797           </xslo:if>
798         </xslo:for-each>
799       </xslo:variable>
800       <xslo:value-of select="normalize-space($raw_heading)"/>
801     </z:index>
802   </xslo:template>
803   <xslo:template mode="index_heading" match="marc:datafield[@tag='182']">
804     <z:index name="Chronological-subdivision:w Chronological-subdivision:p Chronological-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
805       <xslo:variable name="raw_heading">
806         <xslo:for-each select="marc:subfield">
807           <xslo:if test="contains('vxyz', @code)" name="Chronological-subdivision:w Chronological-subdivision:p Chronological-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
808             <xslo:if test="position() &gt; 1">
809               <xslo:choose>
810                 <xslo:when test="contains('vxyz', @code)">
811                   <xslo:text>--</xslo:text>
812                 </xslo:when>
813                 <xslo:otherwise>
814                   <xslo:value-of select="substring(' ', 1, 1)"/>
815                 </xslo:otherwise>
816               </xslo:choose>
817             </xslo:if>
818             <xslo:value-of select="."/>
819           </xslo:if>
820         </xslo:for-each>
821       </xslo:variable>
822       <xslo:value-of select="normalize-space($raw_heading)"/>
823     </z:index>
824   </xslo:template>
825   <xslo:template mode="index_heading" match="marc:datafield[@tag='482']">
826     <z:index name="Chronological-subdivision-see-from:w Chronological-subdivision-see-from:p Chronological-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
827       <xslo:variable name="raw_heading">
828         <xslo:for-each select="marc:subfield">
829           <xslo:if test="contains('vxyz', @code)" name="Chronological-subdivision-see-from:w Chronological-subdivision-see-from:p Chronological-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
830             <xslo:if test="position() &gt; 1">
831               <xslo:choose>
832                 <xslo:when test="contains('vxyz', @code)">
833                   <xslo:text>--</xslo:text>
834                 </xslo:when>
835                 <xslo:otherwise>
836                   <xslo:value-of select="substring(' ', 1, 1)"/>
837                 </xslo:otherwise>
838               </xslo:choose>
839             </xslo:if>
840             <xslo:value-of select="."/>
841           </xslo:if>
842         </xslo:for-each>
843       </xslo:variable>
844       <xslo:value-of select="normalize-space($raw_heading)"/>
845     </z:index>
846   </xslo:template>
847   <xslo:template mode="index_heading" match="marc:datafield[@tag='582']">
848     <z:index name="Chronological-subdivision-see-also-from:w Chronological-subdivision-see-also-from:p Chronological-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
849       <xslo:variable name="raw_heading">
850         <xslo:for-each select="marc:subfield">
851           <xslo:if test="contains('vxyz', @code)" name="Chronological-subdivision-see-also-from:w Chronological-subdivision-see-also-from:p Chronological-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
852             <xslo:if test="position() &gt; 1">
853               <xslo:choose>
854                 <xslo:when test="contains('vxyz', @code)">
855                   <xslo:text>--</xslo:text>
856                 </xslo:when>
857                 <xslo:otherwise>
858                   <xslo:value-of select="substring(' ', 1, 1)"/>
859                 </xslo:otherwise>
860               </xslo:choose>
861             </xslo:if>
862             <xslo:value-of select="."/>
863           </xslo:if>
864         </xslo:for-each>
865       </xslo:variable>
866       <xslo:value-of select="normalize-space($raw_heading)"/>
867     </z:index>
868   </xslo:template>
869   <xslo:template mode="index_heading" match="marc:datafield[@tag='185']">
870     <z:index name="Form-subdivision:w Form-subdivision:p Form-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
871       <xslo:variable name="raw_heading">
872         <xslo:for-each select="marc:subfield">
873           <xslo:if test="contains('vxyz', @code)" name="Form-subdivision:w Form-subdivision:p Form-subdivision:s Subdivision:w Subdivision:p Subdivision:s">
874             <xslo:if test="position() &gt; 1">
875               <xslo:choose>
876                 <xslo:when test="contains('vxyz', @code)">
877                   <xslo:text>--</xslo:text>
878                 </xslo:when>
879                 <xslo:otherwise>
880                   <xslo:value-of select="substring(' ', 1, 1)"/>
881                 </xslo:otherwise>
882               </xslo:choose>
883             </xslo:if>
884             <xslo:value-of select="."/>
885           </xslo:if>
886         </xslo:for-each>
887       </xslo:variable>
888       <xslo:value-of select="normalize-space($raw_heading)"/>
889     </z:index>
890   </xslo:template>
891   <xslo:template mode="index_heading" match="marc:datafield[@tag='485']">
892     <z:index name="Form-subdivision-see-from:w Form-subdivision-see-from:p Form-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
893       <xslo:variable name="raw_heading">
894         <xslo:for-each select="marc:subfield">
895           <xslo:if test="contains('vxyz', @code)" name="Form-subdivision-see-from:w Form-subdivision-see-from:p Form-subdivision-see-from:s Subdivision-see-from:w Subdivision-see-from:p Subdivision-see-from:s">
896             <xslo:if test="position() &gt; 1">
897               <xslo:choose>
898                 <xslo:when test="contains('vxyz', @code)">
899                   <xslo:text>--</xslo:text>
900                 </xslo:when>
901                 <xslo:otherwise>
902                   <xslo:value-of select="substring(' ', 1, 1)"/>
903                 </xslo:otherwise>
904               </xslo:choose>
905             </xslo:if>
906             <xslo:value-of select="."/>
907           </xslo:if>
908         </xslo:for-each>
909       </xslo:variable>
910       <xslo:value-of select="normalize-space($raw_heading)"/>
911     </z:index>
912   </xslo:template>
913   <xslo:template mode="index_heading" match="marc:datafield[@tag='585']">
914     <z:index name="Form-subdivision-see-also-from:w Form-subdivision-see-also-from:p Form-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
915       <xslo:variable name="raw_heading">
916         <xslo:for-each select="marc:subfield">
917           <xslo:if test="contains('vxyz', @code)" name="Form-subdivision-see-also-from:w Form-subdivision-see-also-from:p Form-subdivision-see-also-from:s Subdivision-see-also-from:w Subdivision-see-also-from:p Subdivision-see-also-from:s">
918             <xslo:if test="position() &gt; 1">
919               <xslo:choose>
920                 <xslo:when test="contains('vxyz', @code)">
921                   <xslo:text>--</xslo:text>
922                 </xslo:when>
923                 <xslo:otherwise>
924                   <xslo:value-of select="substring(' ', 1, 1)"/>
925                 </xslo:otherwise>
926               </xslo:choose>
927             </xslo:if>
928             <xslo:value-of select="."/>
929           </xslo:if>
930         </xslo:for-each>
931       </xslo:variable>
932       <xslo:value-of select="normalize-space($raw_heading)"/>
933     </z:index>
934   </xslo:template>
935   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='100']">
936     <z:index name="Match-heading:p Match-heading:s">
937       <xslo:variable name="raw_heading">
938         <xslo:for-each select="marc:subfield">
939           <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Match-heading:p Match-heading:s">
940             <xslo:if test="position() &gt; 1">
941               <xslo:choose>
942                 <xslo:when test="contains('vxyz', @code)">
943                   <xslo:choose>
944                     <xslo:when test="@code = $general_subdivision_subfield">
945                       <xslo:text> generalsubdiv </xslo:text>
946                     </xslo:when>
947                     <xslo:when test="@code = $form_subdivision_subfield">
948                       <xslo:text> formsubdiv </xslo:text>
949                     </xslo:when>
950                     <xslo:when test="@code = $chronological_subdivision_subfield">
951                       <xslo:text> chronologicalsubdiv </xslo:text>
952                     </xslo:when>
953                     <xslo:when test="@code = $geographic_subdivision_subfield">
954                       <xslo:text> geographicsubdiv </xslo:text>
955                     </xslo:when>
956                   </xslo:choose>
957                 </xslo:when>
958                 <xslo:otherwise>
959                   <xslo:value-of select="substring(' ', 1, 1)"/>
960                 </xslo:otherwise>
961               </xslo:choose>
962             </xslo:if>
963             <xslo:value-of select="."/>
964           </xslo:if>
965         </xslo:for-each>
966       </xslo:variable>
967       <xslo:value-of select="normalize-space($raw_heading)"/>
968     </z:index>
969   </xslo:template>
970   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='400']">
971     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
972       <xslo:variable name="raw_heading">
973         <xslo:for-each select="marc:subfield">
974           <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
975             <xslo:if test="position() &gt; 1">
976               <xslo:choose>
977                 <xslo:when test="contains('vxyz', @code)">
978                   <xslo:choose>
979                     <xslo:when test="@code = $general_subdivision_subfield">
980                       <xslo:text> generalsubdiv </xslo:text>
981                     </xslo:when>
982                     <xslo:when test="@code = $form_subdivision_subfield">
983                       <xslo:text> formsubdiv </xslo:text>
984                     </xslo:when>
985                     <xslo:when test="@code = $chronological_subdivision_subfield">
986                       <xslo:text> chronologicalsubdiv </xslo:text>
987                     </xslo:when>
988                     <xslo:when test="@code = $geographic_subdivision_subfield">
989                       <xslo:text> geographicsubdiv </xslo:text>
990                     </xslo:when>
991                   </xslo:choose>
992                 </xslo:when>
993                 <xslo:otherwise>
994                   <xslo:value-of select="substring(' ', 1, 1)"/>
995                 </xslo:otherwise>
996               </xslo:choose>
997             </xslo:if>
998             <xslo:value-of select="."/>
999           </xslo:if>
1000         </xslo:for-each>
1001       </xslo:variable>
1002       <xslo:value-of select="normalize-space($raw_heading)"/>
1003     </z:index>
1004   </xslo:template>
1005   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='110']">
1006     <z:index name="Match-heading:p Match-heading:s">
1007       <xslo:variable name="raw_heading">
1008         <xslo:for-each select="marc:subfield">
1009           <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Match-heading:p Match-heading:s">
1010             <xslo:if test="position() &gt; 1">
1011               <xslo:choose>
1012                 <xslo:when test="contains('vxyz', @code)">
1013                   <xslo:choose>
1014                     <xslo:when test="@code = $general_subdivision_subfield">
1015                       <xslo:text> generalsubdiv </xslo:text>
1016                     </xslo:when>
1017                     <xslo:when test="@code = $form_subdivision_subfield">
1018                       <xslo:text> formsubdiv </xslo:text>
1019                     </xslo:when>
1020                     <xslo:when test="@code = $chronological_subdivision_subfield">
1021                       <xslo:text> chronologicalsubdiv </xslo:text>
1022                     </xslo:when>
1023                     <xslo:when test="@code = $geographic_subdivision_subfield">
1024                       <xslo:text> geographicsubdiv </xslo:text>
1025                     </xslo:when>
1026                   </xslo:choose>
1027                 </xslo:when>
1028                 <xslo:otherwise>
1029                   <xslo:value-of select="substring(' ', 1, 1)"/>
1030                 </xslo:otherwise>
1031               </xslo:choose>
1032             </xslo:if>
1033             <xslo:value-of select="."/>
1034           </xslo:if>
1035         </xslo:for-each>
1036       </xslo:variable>
1037       <xslo:value-of select="normalize-space($raw_heading)"/>
1038     </z:index>
1039   </xslo:template>
1040   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='410']">
1041     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1042       <xslo:variable name="raw_heading">
1043         <xslo:for-each select="marc:subfield">
1044           <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1045             <xslo:if test="position() &gt; 1">
1046               <xslo:choose>
1047                 <xslo:when test="contains('vxyz', @code)">
1048                   <xslo:choose>
1049                     <xslo:when test="@code = $general_subdivision_subfield">
1050                       <xslo:text> generalsubdiv </xslo:text>
1051                     </xslo:when>
1052                     <xslo:when test="@code = $form_subdivision_subfield">
1053                       <xslo:text> formsubdiv </xslo:text>
1054                     </xslo:when>
1055                     <xslo:when test="@code = $chronological_subdivision_subfield">
1056                       <xslo:text> chronologicalsubdiv </xslo:text>
1057                     </xslo:when>
1058                     <xslo:when test="@code = $geographic_subdivision_subfield">
1059                       <xslo:text> geographicsubdiv </xslo:text>
1060                     </xslo:when>
1061                   </xslo:choose>
1062                 </xslo:when>
1063                 <xslo:otherwise>
1064                   <xslo:value-of select="substring(' ', 1, 1)"/>
1065                 </xslo:otherwise>
1066               </xslo:choose>
1067             </xslo:if>
1068             <xslo:value-of select="."/>
1069           </xslo:if>
1070         </xslo:for-each>
1071       </xslo:variable>
1072       <xslo:value-of select="normalize-space($raw_heading)"/>
1073     </z:index>
1074   </xslo:template>
1075   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='111']">
1076     <z:index name="Match-heading:p Match-heading:s">
1077       <xslo:variable name="raw_heading">
1078         <xslo:for-each select="marc:subfield">
1079           <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Match-heading:p Match-heading:s">
1080             <xslo:if test="position() &gt; 1">
1081               <xslo:choose>
1082                 <xslo:when test="contains('vxyz', @code)">
1083                   <xslo:choose>
1084                     <xslo:when test="@code = $general_subdivision_subfield">
1085                       <xslo:text> generalsubdiv </xslo:text>
1086                     </xslo:when>
1087                     <xslo:when test="@code = $form_subdivision_subfield">
1088                       <xslo:text> formsubdiv </xslo:text>
1089                     </xslo:when>
1090                     <xslo:when test="@code = $chronological_subdivision_subfield">
1091                       <xslo:text> chronologicalsubdiv </xslo:text>
1092                     </xslo:when>
1093                     <xslo:when test="@code = $geographic_subdivision_subfield">
1094                       <xslo:text> geographicsubdiv </xslo:text>
1095                     </xslo:when>
1096                   </xslo:choose>
1097                 </xslo:when>
1098                 <xslo:otherwise>
1099                   <xslo:value-of select="substring(' ', 1, 1)"/>
1100                 </xslo:otherwise>
1101               </xslo:choose>
1102             </xslo:if>
1103             <xslo:value-of select="."/>
1104           </xslo:if>
1105         </xslo:for-each>
1106       </xslo:variable>
1107       <xslo:value-of select="normalize-space($raw_heading)"/>
1108     </z:index>
1109   </xslo:template>
1110   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='411']">
1111     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1112       <xslo:variable name="raw_heading">
1113         <xslo:for-each select="marc:subfield">
1114           <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1115             <xslo:if test="position() &gt; 1">
1116               <xslo:choose>
1117                 <xslo:when test="contains('vxyz', @code)">
1118                   <xslo:choose>
1119                     <xslo:when test="@code = $general_subdivision_subfield">
1120                       <xslo:text> generalsubdiv </xslo:text>
1121                     </xslo:when>
1122                     <xslo:when test="@code = $form_subdivision_subfield">
1123                       <xslo:text> formsubdiv </xslo:text>
1124                     </xslo:when>
1125                     <xslo:when test="@code = $chronological_subdivision_subfield">
1126                       <xslo:text> chronologicalsubdiv </xslo:text>
1127                     </xslo:when>
1128                     <xslo:when test="@code = $geographic_subdivision_subfield">
1129                       <xslo:text> geographicsubdiv </xslo:text>
1130                     </xslo:when>
1131                   </xslo:choose>
1132                 </xslo:when>
1133                 <xslo:otherwise>
1134                   <xslo:value-of select="substring(' ', 1, 1)"/>
1135                 </xslo:otherwise>
1136               </xslo:choose>
1137             </xslo:if>
1138             <xslo:value-of select="."/>
1139           </xslo:if>
1140         </xslo:for-each>
1141       </xslo:variable>
1142       <xslo:value-of select="normalize-space($raw_heading)"/>
1143     </z:index>
1144   </xslo:template>
1145   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='130']">
1146     <z:index name="Match-heading:p Match-heading:s">
1147       <xslo:variable name="raw_heading">
1148         <xslo:for-each select="marc:subfield">
1149           <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Match-heading:p Match-heading:s">
1150             <xslo:if test="position() &gt; 1">
1151               <xslo:choose>
1152                 <xslo:when test="contains('vxyz', @code)">
1153                   <xslo:choose>
1154                     <xslo:when test="@code = $general_subdivision_subfield">
1155                       <xslo:text> generalsubdiv </xslo:text>
1156                     </xslo:when>
1157                     <xslo:when test="@code = $form_subdivision_subfield">
1158                       <xslo:text> formsubdiv </xslo:text>
1159                     </xslo:when>
1160                     <xslo:when test="@code = $chronological_subdivision_subfield">
1161                       <xslo:text> chronologicalsubdiv </xslo:text>
1162                     </xslo:when>
1163                     <xslo:when test="@code = $geographic_subdivision_subfield">
1164                       <xslo:text> geographicsubdiv </xslo:text>
1165                     </xslo:when>
1166                   </xslo:choose>
1167                 </xslo:when>
1168                 <xslo:otherwise>
1169                   <xslo:value-of select="substring(' ', 1, 1)"/>
1170                 </xslo:otherwise>
1171               </xslo:choose>
1172             </xslo:if>
1173             <xslo:value-of select="."/>
1174           </xslo:if>
1175         </xslo:for-each>
1176       </xslo:variable>
1177       <xslo:value-of select="normalize-space($raw_heading)"/>
1178     </z:index>
1179   </xslo:template>
1180   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='430']">
1181     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1182       <xslo:variable name="raw_heading">
1183         <xslo:for-each select="marc:subfield">
1184           <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1185             <xslo:if test="position() &gt; 1">
1186               <xslo:choose>
1187                 <xslo:when test="contains('vxyz', @code)">
1188                   <xslo:choose>
1189                     <xslo:when test="@code = $general_subdivision_subfield">
1190                       <xslo:text> generalsubdiv </xslo:text>
1191                     </xslo:when>
1192                     <xslo:when test="@code = $form_subdivision_subfield">
1193                       <xslo:text> formsubdiv </xslo:text>
1194                     </xslo:when>
1195                     <xslo:when test="@code = $chronological_subdivision_subfield">
1196                       <xslo:text> chronologicalsubdiv </xslo:text>
1197                     </xslo:when>
1198                     <xslo:when test="@code = $geographic_subdivision_subfield">
1199                       <xslo:text> geographicsubdiv </xslo:text>
1200                     </xslo:when>
1201                   </xslo:choose>
1202                 </xslo:when>
1203                 <xslo:otherwise>
1204                   <xslo:value-of select="substring(' ', 1, 1)"/>
1205                 </xslo:otherwise>
1206               </xslo:choose>
1207             </xslo:if>
1208             <xslo:value-of select="."/>
1209           </xslo:if>
1210         </xslo:for-each>
1211       </xslo:variable>
1212       <xslo:value-of select="normalize-space($raw_heading)"/>
1213     </z:index>
1214   </xslo:template>
1215   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='148']">
1216     <z:index name="Match-heading:p Match-heading:s">
1217       <xslo:variable name="raw_heading">
1218         <xslo:for-each select="marc:subfield">
1219           <xslo:if test="contains('avxyz', @code)" name="Match-heading:p Match-heading:s">
1220             <xslo:if test="position() &gt; 1">
1221               <xslo:choose>
1222                 <xslo:when test="contains('vxyz', @code)">
1223                   <xslo:choose>
1224                     <xslo:when test="@code = $general_subdivision_subfield">
1225                       <xslo:text> generalsubdiv </xslo:text>
1226                     </xslo:when>
1227                     <xslo:when test="@code = $form_subdivision_subfield">
1228                       <xslo:text> formsubdiv </xslo:text>
1229                     </xslo:when>
1230                     <xslo:when test="@code = $chronological_subdivision_subfield">
1231                       <xslo:text> chronologicalsubdiv </xslo:text>
1232                     </xslo:when>
1233                     <xslo:when test="@code = $geographic_subdivision_subfield">
1234                       <xslo:text> geographicsubdiv </xslo:text>
1235                     </xslo:when>
1236                   </xslo:choose>
1237                 </xslo:when>
1238                 <xslo:otherwise>
1239                   <xslo:value-of select="substring(' ', 1, 1)"/>
1240                 </xslo:otherwise>
1241               </xslo:choose>
1242             </xslo:if>
1243             <xslo:value-of select="."/>
1244           </xslo:if>
1245         </xslo:for-each>
1246       </xslo:variable>
1247       <xslo:value-of select="normalize-space($raw_heading)"/>
1248     </z:index>
1249   </xslo:template>
1250   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='448']">
1251     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1252       <xslo:variable name="raw_heading">
1253         <xslo:for-each select="marc:subfield">
1254           <xslo:if test="contains('avxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1255             <xslo:if test="position() &gt; 1">
1256               <xslo:choose>
1257                 <xslo:when test="contains('vxyz', @code)">
1258                   <xslo:choose>
1259                     <xslo:when test="@code = $general_subdivision_subfield">
1260                       <xslo:text> generalsubdiv </xslo:text>
1261                     </xslo:when>
1262                     <xslo:when test="@code = $form_subdivision_subfield">
1263                       <xslo:text> formsubdiv </xslo:text>
1264                     </xslo:when>
1265                     <xslo:when test="@code = $chronological_subdivision_subfield">
1266                       <xslo:text> chronologicalsubdiv </xslo:text>
1267                     </xslo:when>
1268                     <xslo:when test="@code = $geographic_subdivision_subfield">
1269                       <xslo:text> geographicsubdiv </xslo:text>
1270                     </xslo:when>
1271                   </xslo:choose>
1272                 </xslo:when>
1273                 <xslo:otherwise>
1274                   <xslo:value-of select="substring(' ', 1, 1)"/>
1275                 </xslo:otherwise>
1276               </xslo:choose>
1277             </xslo:if>
1278             <xslo:value-of select="."/>
1279           </xslo:if>
1280         </xslo:for-each>
1281       </xslo:variable>
1282       <xslo:value-of select="normalize-space($raw_heading)"/>
1283     </z:index>
1284   </xslo:template>
1285   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='150']">
1286     <z:index name="Match-heading:p Match-heading:s">
1287       <xslo:variable name="raw_heading">
1288         <xslo:for-each select="marc:subfield">
1289           <xslo:if test="contains('abvxyz', @code)" name="Match-heading:p Match-heading:s">
1290             <xslo:if test="position() &gt; 1">
1291               <xslo:choose>
1292                 <xslo:when test="contains('vxyz', @code)">
1293                   <xslo:choose>
1294                     <xslo:when test="@code = $general_subdivision_subfield">
1295                       <xslo:text> generalsubdiv </xslo:text>
1296                     </xslo:when>
1297                     <xslo:when test="@code = $form_subdivision_subfield">
1298                       <xslo:text> formsubdiv </xslo:text>
1299                     </xslo:when>
1300                     <xslo:when test="@code = $chronological_subdivision_subfield">
1301                       <xslo:text> chronologicalsubdiv </xslo:text>
1302                     </xslo:when>
1303                     <xslo:when test="@code = $geographic_subdivision_subfield">
1304                       <xslo:text> geographicsubdiv </xslo:text>
1305                     </xslo:when>
1306                   </xslo:choose>
1307                 </xslo:when>
1308                 <xslo:otherwise>
1309                   <xslo:value-of select="substring(' ', 1, 1)"/>
1310                 </xslo:otherwise>
1311               </xslo:choose>
1312             </xslo:if>
1313             <xslo:value-of select="."/>
1314           </xslo:if>
1315         </xslo:for-each>
1316       </xslo:variable>
1317       <xslo:value-of select="normalize-space($raw_heading)"/>
1318     </z:index>
1319   </xslo:template>
1320   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='450']">
1321     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1322       <xslo:variable name="raw_heading">
1323         <xslo:for-each select="marc:subfield">
1324           <xslo:if test="contains('abvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1325             <xslo:if test="position() &gt; 1">
1326               <xslo:choose>
1327                 <xslo:when test="contains('vxyz', @code)">
1328                   <xslo:choose>
1329                     <xslo:when test="@code = $general_subdivision_subfield">
1330                       <xslo:text> generalsubdiv </xslo:text>
1331                     </xslo:when>
1332                     <xslo:when test="@code = $form_subdivision_subfield">
1333                       <xslo:text> formsubdiv </xslo:text>
1334                     </xslo:when>
1335                     <xslo:when test="@code = $chronological_subdivision_subfield">
1336                       <xslo:text> chronologicalsubdiv </xslo:text>
1337                     </xslo:when>
1338                     <xslo:when test="@code = $geographic_subdivision_subfield">
1339                       <xslo:text> geographicsubdiv </xslo:text>
1340                     </xslo:when>
1341                   </xslo:choose>
1342                 </xslo:when>
1343                 <xslo:otherwise>
1344                   <xslo:value-of select="substring(' ', 1, 1)"/>
1345                 </xslo:otherwise>
1346               </xslo:choose>
1347             </xslo:if>
1348             <xslo:value-of select="."/>
1349           </xslo:if>
1350         </xslo:for-each>
1351       </xslo:variable>
1352       <xslo:value-of select="normalize-space($raw_heading)"/>
1353     </z:index>
1354   </xslo:template>
1355   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='151']">
1356     <z:index name="Match-heading:p Match-heading:s">
1357       <xslo:variable name="raw_heading">
1358         <xslo:for-each select="marc:subfield">
1359           <xslo:if test="contains('avxyz', @code)" name="Match-heading:p Match-heading:s">
1360             <xslo:if test="position() &gt; 1">
1361               <xslo:choose>
1362                 <xslo:when test="contains('vxyz', @code)">
1363                   <xslo:choose>
1364                     <xslo:when test="@code = $general_subdivision_subfield">
1365                       <xslo:text> generalsubdiv </xslo:text>
1366                     </xslo:when>
1367                     <xslo:when test="@code = $form_subdivision_subfield">
1368                       <xslo:text> formsubdiv </xslo:text>
1369                     </xslo:when>
1370                     <xslo:when test="@code = $chronological_subdivision_subfield">
1371                       <xslo:text> chronologicalsubdiv </xslo:text>
1372                     </xslo:when>
1373                     <xslo:when test="@code = $geographic_subdivision_subfield">
1374                       <xslo:text> geographicsubdiv </xslo:text>
1375                     </xslo:when>
1376                   </xslo:choose>
1377                 </xslo:when>
1378                 <xslo:otherwise>
1379                   <xslo:value-of select="substring(' ', 1, 1)"/>
1380                 </xslo:otherwise>
1381               </xslo:choose>
1382             </xslo:if>
1383             <xslo:value-of select="."/>
1384           </xslo:if>
1385         </xslo:for-each>
1386       </xslo:variable>
1387       <xslo:value-of select="normalize-space($raw_heading)"/>
1388     </z:index>
1389   </xslo:template>
1390   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='451']">
1391     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1392       <xslo:variable name="raw_heading">
1393         <xslo:for-each select="marc:subfield">
1394           <xslo:if test="contains('avxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1395             <xslo:if test="position() &gt; 1">
1396               <xslo:choose>
1397                 <xslo:when test="contains('vxyz', @code)">
1398                   <xslo:choose>
1399                     <xslo:when test="@code = $general_subdivision_subfield">
1400                       <xslo:text> generalsubdiv </xslo:text>
1401                     </xslo:when>
1402                     <xslo:when test="@code = $form_subdivision_subfield">
1403                       <xslo:text> formsubdiv </xslo:text>
1404                     </xslo:when>
1405                     <xslo:when test="@code = $chronological_subdivision_subfield">
1406                       <xslo:text> chronologicalsubdiv </xslo:text>
1407                     </xslo:when>
1408                     <xslo:when test="@code = $geographic_subdivision_subfield">
1409                       <xslo:text> geographicsubdiv </xslo:text>
1410                     </xslo:when>
1411                   </xslo:choose>
1412                 </xslo:when>
1413                 <xslo:otherwise>
1414                   <xslo:value-of select="substring(' ', 1, 1)"/>
1415                 </xslo:otherwise>
1416               </xslo:choose>
1417             </xslo:if>
1418             <xslo:value-of select="."/>
1419           </xslo:if>
1420         </xslo:for-each>
1421       </xslo:variable>
1422       <xslo:value-of select="normalize-space($raw_heading)"/>
1423     </z:index>
1424   </xslo:template>
1425   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='155']">
1426     <z:index name="Match-heading:p Match-heading:s">
1427       <xslo:variable name="raw_heading">
1428         <xslo:for-each select="marc:subfield">
1429           <xslo:if test="contains('avxyz', @code)" name="Match-heading:p Match-heading:s">
1430             <xslo:if test="position() &gt; 1">
1431               <xslo:choose>
1432                 <xslo:when test="contains('vxyz', @code)">
1433                   <xslo:choose>
1434                     <xslo:when test="@code = $general_subdivision_subfield">
1435                       <xslo:text> generalsubdiv </xslo:text>
1436                     </xslo:when>
1437                     <xslo:when test="@code = $form_subdivision_subfield">
1438                       <xslo:text> formsubdiv </xslo:text>
1439                     </xslo:when>
1440                     <xslo:when test="@code = $chronological_subdivision_subfield">
1441                       <xslo:text> chronologicalsubdiv </xslo:text>
1442                     </xslo:when>
1443                     <xslo:when test="@code = $geographic_subdivision_subfield">
1444                       <xslo:text> geographicsubdiv </xslo:text>
1445                     </xslo:when>
1446                   </xslo:choose>
1447                 </xslo:when>
1448                 <xslo:otherwise>
1449                   <xslo:value-of select="substring(' ', 1, 1)"/>
1450                 </xslo:otherwise>
1451               </xslo:choose>
1452             </xslo:if>
1453             <xslo:value-of select="."/>
1454           </xslo:if>
1455         </xslo:for-each>
1456       </xslo:variable>
1457       <xslo:value-of select="normalize-space($raw_heading)"/>
1458     </z:index>
1459   </xslo:template>
1460   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='455']">
1461     <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
1462       <xslo:variable name="raw_heading">
1463         <xslo:for-each select="marc:subfield">
1464           <xslo:if test="contains('avxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
1465             <xslo:if test="position() &gt; 1">
1466               <xslo:choose>
1467                 <xslo:when test="contains('vxyz', @code)">
1468                   <xslo:choose>
1469                     <xslo:when test="@code = $general_subdivision_subfield">
1470                       <xslo:text> generalsubdiv </xslo:text>
1471                     </xslo:when>
1472                     <xslo:when test="@code = $form_subdivision_subfield">
1473                       <xslo:text> formsubdiv </xslo:text>
1474                     </xslo:when>
1475                     <xslo:when test="@code = $chronological_subdivision_subfield">
1476                       <xslo:text> chronologicalsubdiv </xslo:text>
1477                     </xslo:when>
1478                     <xslo:when test="@code = $geographic_subdivision_subfield">
1479                       <xslo:text> geographicsubdiv </xslo:text>
1480                     </xslo:when>
1481                   </xslo:choose>
1482                 </xslo:when>
1483                 <xslo:otherwise>
1484                   <xslo:value-of select="substring(' ', 1, 1)"/>
1485                 </xslo:otherwise>
1486               </xslo:choose>
1487             </xslo:if>
1488             <xslo:value-of select="."/>
1489           </xslo:if>
1490         </xslo:for-each>
1491       </xslo:variable>
1492       <xslo:value-of select="normalize-space($raw_heading)"/>
1493     </z:index>
1494   </xslo:template>
1495   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='180']">
1496     <z:index name="Match-subdivision:p Match-subdivision:s">
1497       <xslo:variable name="raw_heading">
1498         <xslo:for-each select="marc:subfield">
1499           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
1500             <xslo:if test="position() &gt; 1">
1501               <xslo:choose>
1502                 <xslo:when test="contains('vxyz', @code)">
1503                   <xslo:choose>
1504                     <xslo:when test="@code = $general_subdivision_subfield">
1505                       <xslo:text> generalsubdiv </xslo:text>
1506                     </xslo:when>
1507                     <xslo:when test="@code = $form_subdivision_subfield">
1508                       <xslo:text> formsubdiv </xslo:text>
1509                     </xslo:when>
1510                     <xslo:when test="@code = $chronological_subdivision_subfield">
1511                       <xslo:text> chronologicalsubdiv </xslo:text>
1512                     </xslo:when>
1513                     <xslo:when test="@code = $geographic_subdivision_subfield">
1514                       <xslo:text> geographicsubdiv </xslo:text>
1515                     </xslo:when>
1516                   </xslo:choose>
1517                 </xslo:when>
1518                 <xslo:otherwise>
1519                   <xslo:value-of select="substring(' ', 1, 1)"/>
1520                 </xslo:otherwise>
1521               </xslo:choose>
1522             </xslo:if>
1523             <xslo:value-of select="."/>
1524           </xslo:if>
1525         </xslo:for-each>
1526       </xslo:variable>
1527       <xslo:value-of select="normalize-space($raw_heading)"/>
1528     </z:index>
1529   </xslo:template>
1530   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='480']">
1531     <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1532       <xslo:variable name="raw_heading">
1533         <xslo:for-each select="marc:subfield">
1534           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1535             <xslo:if test="position() &gt; 1">
1536               <xslo:choose>
1537                 <xslo:when test="contains('vxyz', @code)">
1538                   <xslo:choose>
1539                     <xslo:when test="@code = $general_subdivision_subfield">
1540                       <xslo:text> generalsubdiv </xslo:text>
1541                     </xslo:when>
1542                     <xslo:when test="@code = $form_subdivision_subfield">
1543                       <xslo:text> formsubdiv </xslo:text>
1544                     </xslo:when>
1545                     <xslo:when test="@code = $chronological_subdivision_subfield">
1546                       <xslo:text> chronologicalsubdiv </xslo:text>
1547                     </xslo:when>
1548                     <xslo:when test="@code = $geographic_subdivision_subfield">
1549                       <xslo:text> geographicsubdiv </xslo:text>
1550                     </xslo:when>
1551                   </xslo:choose>
1552                 </xslo:when>
1553                 <xslo:otherwise>
1554                   <xslo:value-of select="substring(' ', 1, 1)"/>
1555                 </xslo:otherwise>
1556               </xslo:choose>
1557             </xslo:if>
1558             <xslo:value-of select="."/>
1559           </xslo:if>
1560         </xslo:for-each>
1561       </xslo:variable>
1562       <xslo:value-of select="normalize-space($raw_heading)"/>
1563     </z:index>
1564   </xslo:template>
1565   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='181']">
1566     <z:index name="Match-subdivision:p Match-subdivision:s">
1567       <xslo:variable name="raw_heading">
1568         <xslo:for-each select="marc:subfield">
1569           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
1570             <xslo:if test="position() &gt; 1">
1571               <xslo:choose>
1572                 <xslo:when test="contains('vxyz', @code)">
1573                   <xslo:choose>
1574                     <xslo:when test="@code = $general_subdivision_subfield">
1575                       <xslo:text> generalsubdiv </xslo:text>
1576                     </xslo:when>
1577                     <xslo:when test="@code = $form_subdivision_subfield">
1578                       <xslo:text> formsubdiv </xslo:text>
1579                     </xslo:when>
1580                     <xslo:when test="@code = $chronological_subdivision_subfield">
1581                       <xslo:text> chronologicalsubdiv </xslo:text>
1582                     </xslo:when>
1583                     <xslo:when test="@code = $geographic_subdivision_subfield">
1584                       <xslo:text> geographicsubdiv </xslo:text>
1585                     </xslo:when>
1586                   </xslo:choose>
1587                 </xslo:when>
1588                 <xslo:otherwise>
1589                   <xslo:value-of select="substring(' ', 1, 1)"/>
1590                 </xslo:otherwise>
1591               </xslo:choose>
1592             </xslo:if>
1593             <xslo:value-of select="."/>
1594           </xslo:if>
1595         </xslo:for-each>
1596       </xslo:variable>
1597       <xslo:value-of select="normalize-space($raw_heading)"/>
1598     </z:index>
1599   </xslo:template>
1600   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='481']">
1601     <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1602       <xslo:variable name="raw_heading">
1603         <xslo:for-each select="marc:subfield">
1604           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1605             <xslo:if test="position() &gt; 1">
1606               <xslo:choose>
1607                 <xslo:when test="contains('vxyz', @code)">
1608                   <xslo:choose>
1609                     <xslo:when test="@code = $general_subdivision_subfield">
1610                       <xslo:text> generalsubdiv </xslo:text>
1611                     </xslo:when>
1612                     <xslo:when test="@code = $form_subdivision_subfield">
1613                       <xslo:text> formsubdiv </xslo:text>
1614                     </xslo:when>
1615                     <xslo:when test="@code = $chronological_subdivision_subfield">
1616                       <xslo:text> chronologicalsubdiv </xslo:text>
1617                     </xslo:when>
1618                     <xslo:when test="@code = $geographic_subdivision_subfield">
1619                       <xslo:text> geographicsubdiv </xslo:text>
1620                     </xslo:when>
1621                   </xslo:choose>
1622                 </xslo:when>
1623                 <xslo:otherwise>
1624                   <xslo:value-of select="substring(' ', 1, 1)"/>
1625                 </xslo:otherwise>
1626               </xslo:choose>
1627             </xslo:if>
1628             <xslo:value-of select="."/>
1629           </xslo:if>
1630         </xslo:for-each>
1631       </xslo:variable>
1632       <xslo:value-of select="normalize-space($raw_heading)"/>
1633     </z:index>
1634   </xslo:template>
1635   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='182']">
1636     <z:index name="Match-subdivision:p Match-subdivision:s">
1637       <xslo:variable name="raw_heading">
1638         <xslo:for-each select="marc:subfield">
1639           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
1640             <xslo:if test="position() &gt; 1">
1641               <xslo:choose>
1642                 <xslo:when test="contains('vxyz', @code)">
1643                   <xslo:choose>
1644                     <xslo:when test="@code = $general_subdivision_subfield">
1645                       <xslo:text> generalsubdiv </xslo:text>
1646                     </xslo:when>
1647                     <xslo:when test="@code = $form_subdivision_subfield">
1648                       <xslo:text> formsubdiv </xslo:text>
1649                     </xslo:when>
1650                     <xslo:when test="@code = $chronological_subdivision_subfield">
1651                       <xslo:text> chronologicalsubdiv </xslo:text>
1652                     </xslo:when>
1653                     <xslo:when test="@code = $geographic_subdivision_subfield">
1654                       <xslo:text> geographicsubdiv </xslo:text>
1655                     </xslo:when>
1656                   </xslo:choose>
1657                 </xslo:when>
1658                 <xslo:otherwise>
1659                   <xslo:value-of select="substring(' ', 1, 1)"/>
1660                 </xslo:otherwise>
1661               </xslo:choose>
1662             </xslo:if>
1663             <xslo:value-of select="."/>
1664           </xslo:if>
1665         </xslo:for-each>
1666       </xslo:variable>
1667       <xslo:value-of select="normalize-space($raw_heading)"/>
1668     </z:index>
1669   </xslo:template>
1670   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='482']">
1671     <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1672       <xslo:variable name="raw_heading">
1673         <xslo:for-each select="marc:subfield">
1674           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1675             <xslo:if test="position() &gt; 1">
1676               <xslo:choose>
1677                 <xslo:when test="contains('vxyz', @code)">
1678                   <xslo:choose>
1679                     <xslo:when test="@code = $general_subdivision_subfield">
1680                       <xslo:text> generalsubdiv </xslo:text>
1681                     </xslo:when>
1682                     <xslo:when test="@code = $form_subdivision_subfield">
1683                       <xslo:text> formsubdiv </xslo:text>
1684                     </xslo:when>
1685                     <xslo:when test="@code = $chronological_subdivision_subfield">
1686                       <xslo:text> chronologicalsubdiv </xslo:text>
1687                     </xslo:when>
1688                     <xslo:when test="@code = $geographic_subdivision_subfield">
1689                       <xslo:text> geographicsubdiv </xslo:text>
1690                     </xslo:when>
1691                   </xslo:choose>
1692                 </xslo:when>
1693                 <xslo:otherwise>
1694                   <xslo:value-of select="substring(' ', 1, 1)"/>
1695                 </xslo:otherwise>
1696               </xslo:choose>
1697             </xslo:if>
1698             <xslo:value-of select="."/>
1699           </xslo:if>
1700         </xslo:for-each>
1701       </xslo:variable>
1702       <xslo:value-of select="normalize-space($raw_heading)"/>
1703     </z:index>
1704   </xslo:template>
1705   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='485']">
1706     <z:index name="Match-subdivision:p Match-subdivision:s">
1707       <xslo:variable name="raw_heading">
1708         <xslo:for-each select="marc:subfield">
1709           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
1710             <xslo:if test="position() &gt; 1">
1711               <xslo:choose>
1712                 <xslo:when test="contains('vxyz', @code)">
1713                   <xslo:choose>
1714                     <xslo:when test="@code = $general_subdivision_subfield">
1715                       <xslo:text> generalsubdiv </xslo:text>
1716                     </xslo:when>
1717                     <xslo:when test="@code = $form_subdivision_subfield">
1718                       <xslo:text> formsubdiv </xslo:text>
1719                     </xslo:when>
1720                     <xslo:when test="@code = $chronological_subdivision_subfield">
1721                       <xslo:text> chronologicalsubdiv </xslo:text>
1722                     </xslo:when>
1723                     <xslo:when test="@code = $geographic_subdivision_subfield">
1724                       <xslo:text> geographicsubdiv </xslo:text>
1725                     </xslo:when>
1726                   </xslo:choose>
1727                 </xslo:when>
1728                 <xslo:otherwise>
1729                   <xslo:value-of select="substring(' ', 1, 1)"/>
1730                 </xslo:otherwise>
1731               </xslo:choose>
1732             </xslo:if>
1733             <xslo:value-of select="."/>
1734           </xslo:if>
1735         </xslo:for-each>
1736       </xslo:variable>
1737       <xslo:value-of select="normalize-space($raw_heading)"/>
1738     </z:index>
1739   </xslo:template>
1740   <xslo:template mode="index_match_heading" match="marc:datafield[@tag='185']">
1741     <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1742       <xslo:variable name="raw_heading">
1743         <xslo:for-each select="marc:subfield">
1744           <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
1745             <xslo:if test="position() &gt; 1">
1746               <xslo:choose>
1747                 <xslo:when test="contains('vxyz', @code)">
1748                   <xslo:choose>
1749                     <xslo:when test="@code = $general_subdivision_subfield">
1750                       <xslo:text> generalsubdiv </xslo:text>
1751                     </xslo:when>
1752                     <xslo:when test="@code = $form_subdivision_subfield">
1753                       <xslo:text> formsubdiv </xslo:text>
1754                     </xslo:when>
1755                     <xslo:when test="@code = $chronological_subdivision_subfield">
1756                       <xslo:text> chronologicalsubdiv </xslo:text>
1757                     </xslo:when>
1758                     <xslo:when test="@code = $geographic_subdivision_subfield">
1759                       <xslo:text> geographicsubdiv </xslo:text>
1760                     </xslo:when>
1761                   </xslo:choose>
1762                 </xslo:when>
1763                 <xslo:otherwise>
1764                   <xslo:value-of select="substring(' ', 1, 1)"/>
1765                 </xslo:otherwise>
1766               </xslo:choose>
1767             </xslo:if>
1768             <xslo:value-of select="."/>
1769           </xslo:if>
1770         </xslo:for-each>
1771       </xslo:variable>
1772       <xslo:value-of select="normalize-space($raw_heading)"/>
1773     </z:index>
1774   </xslo:template>
1775   <xslo:variable name="form_subdivision_subfield">v</xslo:variable>
1776   <xslo:variable name="general_subdivision_subfield">x</xslo:variable>
1777   <xslo:variable name="chronological_subdivision_subfield">y</xslo:variable>
1778   <xslo:variable name="geographic_subdivision_subfield">z</xslo:variable>
1779   <xslo:template mode="index_subject_thesaurus" match="marc:controlfield[@tag='008']">
1780     <xslo:variable name="thesaurus_code1" select="substring(., 12, 1)"/>
1781     <xslo:variable name="full_thesaurus_code">
1782       <xslo:choose>
1783         <xslo:when test="$thesaurus_code1 = 'a'">
1784           <xslo:text>lcsh</xslo:text>
1785         </xslo:when>
1786         <xslo:when test="$thesaurus_code1 = 'b'">
1787           <xslo:text>lcac</xslo:text>
1788         </xslo:when>
1789         <xslo:when test="$thesaurus_code1 = 'c'">
1790           <xslo:text>mesh</xslo:text>
1791         </xslo:when>
1792         <xslo:when test="$thesaurus_code1 = 'd'">
1793           <xslo:text>nal</xslo:text>
1794         </xslo:when>
1795         <xslo:when test="$thesaurus_code1 = 'k'">
1796           <xslo:text>cash</xslo:text>
1797         </xslo:when>
1798         <xslo:when test="$thesaurus_code1 = 'n'">
1799           <xslo:text>notapplicable</xslo:text>
1800         </xslo:when>
1801         <xslo:when test="$thesaurus_code1 = 'r'">
1802           <xslo:text>aat</xslo:text>
1803         </xslo:when>
1804         <xslo:when test="$thesaurus_code1 = 's'">
1805           <xslo:text>sears</xslo:text>
1806         </xslo:when>
1807         <xslo:when test="$thesaurus_code1 = 'v'">
1808           <xslo:text>rvm</xslo:text>
1809         </xslo:when>
1810         <xslo:when test="$thesaurus_code1 = 'z'">
1811           <xslo:choose>
1812             <xslo:when test="//marc:datafield[@tag='040']/marc:subfield[@code='f']">
1813               <xslo:value-of select="//marc:datafield[@tag='040']/marc:subfield[@code='f']"/>
1814             </xslo:when>
1815             <xslo:otherwise>
1816               <xslo:text>notdefined</xslo:text>
1817             </xslo:otherwise>
1818           </xslo:choose>
1819         </xslo:when>
1820         <xslo:otherwise>
1821           <xslo:text>notdefined</xslo:text>
1822         </xslo:otherwise>
1823       </xslo:choose>
1824     </xslo:variable>
1825     <z:index name="Subject-heading-thesaurus:w">
1826       <xslo:value-of select="$full_thesaurus_code"/>
1827     </z:index>
1828   </xslo:template>
1829 </xslo:stylesheet>