Merge remote-tracking branch 'kc/new/enh/bug_5579' into kcmaster
[koha.git] / etc / zebradb / marc_defs / marc21 / authorities / authority-zebra-indexdefs.xsl
index f1c4dc7..5c37bc6 100644 (file)
@@ -1,9 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<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">
+<!--
+This file has been automatically generated from a Koha index definition file
+with the stylesheet koha-indexdefs-to-zebra.xsl. Do not manually edit this file,
+as it may be overwritten. To regenerate, edit the appropriate Koha index
+definition file (probably something like authority-koha-indexdefs.xml) and run:
+`xsltproc koha-indexdefs-to-zebra.xsl authority-koha-indexdefs.xml >
+authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
+-->
+<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-community.org/schemas/index-defs" version="1.0">
   <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
   <xslo:template match="text()"/>
   <xslo:template match="text()" mode="index_subfields"/>
   <xslo:template match="text()" mode="index_heading"/>
+  <xslo:template match="text()" mode="index_match_heading"/>
   <xslo:template match="text()" mode="index_subject_thesaurus"/>
   <xslo:template match="/">
     <xslo:if test="marc:collection">
       <xslo:apply-templates/>
       <xslo:apply-templates mode="index_subfields"/>
       <xslo:apply-templates mode="index_heading"/>
+      <xslo:apply-templates mode="index_match_heading"/>
       <xslo:apply-templates mode="index_subject_thesaurus"/>
     </z:record>
   </xslo:template>
   <xslo:template match="marc:leader">
-    <z:index name="Record-status">
+    <z:index name="Record-status:w">
       <xslo:value-of select="substring(., 6, 1)"/>
     </z:index>
-    <z:index name="Encoding-level">
+    <z:index name="Encoding-level:w">
       <xslo:value-of select="substring(., 18, 1)"/>
     </z:index>
   </xslo:template>
   <xslo:template match="marc:controlfield[@tag='001']">
-    <z:index name="Local-Number">
+    <z:index name="Local-Number:w">
       <xslo:value-of select="."/>
     </z:index>
   </xslo:template>
   <xslo:template match="marc:controlfield[@tag='008']">
-    <z:index name="Kind-of-record">
+    <z:index name="Kind-of-record:w">
       <xslo:value-of select="substring(., 10, 1)"/>
     </z:index>
-    <z:index name="Descriptive-cataloging-rules">
+    <z:index name="Descriptive-cataloging-rules:w">
       <xslo:value-of select="substring(., 11, 1)"/>
     </z:index>
-    <z:index name="Heading-use-main-or-added-entry">
+    <z:index name="Heading-use-main-or-added-entry:w">
       <xslo:value-of select="substring(., 15, 1)"/>
     </z:index>
-    <z:index name="Heading-use-subject-added-entry">
+    <z:index name="Heading-use-subject-added-entry:w">
       <xslo:value-of select="substring(., 16, 1)"/>
     </z:index>
-    <z:index name="Heading-use-series-added-entry">
+    <z:index name="Heading-use-series-added-entry:w">
       <xslo:value-of select="substring(., 17, 1)"/>
     </z:index>
   </xslo:template>
   <xslo:template mode="index_subfields" match="marc:datafield[@tag='942']">
     <xslo:for-each select="marc:subfield">
       <xslo:if test="contains('a', @code)">
-        <z:index name="authtype">
+        <z:index name="authtype:w">
           <xslo:value-of select="."/>
         </z:index>
       </xslo:if>
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='400']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='410']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='411']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='430']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='448']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='450']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='451']">
     <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">
       </xslo:variable>
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
+    <z:index name="Heading-Main:w Heading-Main:p Heading-Main:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('a', @code)" name="Heading-Main:w Heading-Main:p Heading-Main:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('', @code)">
+                  <xslo:text>--</xslo:text>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
   </xslo:template>
   <xslo:template mode="index_heading" match="marc:datafield[@tag='455']">
     <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">
       <xslo:value-of select="normalize-space($raw_heading)"/>
     </z:index>
   </xslo:template>
-  <xslo:template mode="index_subject_thesaurus" match="marc:controlfield[@tag='008']">
-    <xslo:variable name="thesaurus_code1" select="substring(., 12, 1)"/>
-    <xslo:variable name="full_thesaurus_code">
-      <xslo:choose>
-        <xslo:when test="$thesaurus_code1 = 'a'">
-          <xslo:text>lcsh</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'b'">
-          <xslo:text>lcac</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'c'">
-          <xslo:text>mesh</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'd'">
-          <xslo:text>nal</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'k'">
-          <xslo:text>cash</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'n'">
-          <xslo:text>notapplicable</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'r'">
-          <xslo:text>aat</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 's'">
-          <xslo:text>sears</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'v'">
-          <xslo:text>rvm</xslo:text>
-        </xslo:when>
-        <xslo:when test="$thesaurus_code1 = 'z'">
-          <xslo:choose>
-            <xslo:when test="//marc:datafield[@tag='040']/marc:subfield[@code='f']">
-              <xslo:value-of select="//marc:datafield[@tag='040']/marc:subfield[@code='f']"/>
-            </xslo:when>
-            <xslo:otherwise>
-              <xslo:text>notdefined</xslo:text>
-            </xslo:otherwise>
-          </xslo:choose>
-        </xslo:when>
-        <xslo:otherwise>
-          <xslo:text>notdefined</xslo:text>
-        </xslo:otherwise>
-      </xslo:choose>
-    </xslo:variable>
-    <z:index name="Subject-heading-thesaurus">
-      <xslo:value-of select="$full_thesaurus_code"/>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='100']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='400']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='110']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='410']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('abcdefghklmnoprstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='111']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='411']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('acdefghjklnpqstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='130']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='430']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('adfghklmnoprstvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='148']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('avxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='448']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('avxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='150']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('abvxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='450']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('abvxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='151']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('avxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='451']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('avxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='155']">
+    <z:index name="Match-heading:p Match-heading:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('avxyz', @code)" name="Match-heading:p Match-heading:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='455']">
+    <z:index name="Match-heading-see-from:p Match-heading-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('avxyz', @code)" name="Match-heading-see-from:p Match-heading-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='180']">
+    <z:index name="Match-subdivision:p Match-subdivision:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='480']">
+    <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='181']">
+    <z:index name="Match-subdivision:p Match-subdivision:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='481']">
+    <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='182']">
+    <z:index name="Match-subdivision:p Match-subdivision:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='482']">
+    <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='485']">
+    <z:index name="Match-subdivision:p Match-subdivision:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision:p Match-subdivision:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template mode="index_match_heading" match="marc:datafield[@tag='185']">
+    <z:index name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+      <xslo:variable name="raw_heading">
+        <xslo:for-each select="marc:subfield">
+          <xslo:if test="contains('vxyz', @code)" name="Match-subdivision-see-from:p Match-subdivision-see-from:s">
+            <xslo:if test="position() &gt; 1">
+              <xslo:choose>
+                <xslo:when test="contains('vxyz', @code)">
+                  <xslo:choose>
+                    <xslo:when test="@code = $general_subdivision_subfield">
+                      <xslo:text> generalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $form_subdivision_subfield">
+                      <xslo:text> formsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $chronological_subdivision_subfield">
+                      <xslo:text> chronologicalsubdiv </xslo:text>
+                    </xslo:when>
+                    <xslo:when test="@code = $geographic_subdivision_subfield">
+                      <xslo:text> geographicsubdiv </xslo:text>
+                    </xslo:when>
+                  </xslo:choose>
+                </xslo:when>
+                <xslo:otherwise>
+                  <xslo:value-of select="substring(' ', 1, 1)"/>
+                </xslo:otherwise>
+              </xslo:choose>
+            </xslo:if>
+            <xslo:value-of select="."/>
+          </xslo:if>
+        </xslo:for-each>
+      </xslo:variable>
+      <xslo:value-of select="normalize-space($raw_heading)"/>
+    </z:index>
+  </xslo:template>
+  <xslo:variable name="form_subdivision_subfield">v</xslo:variable>
+  <xslo:variable name="general_subdivision_subfield">x</xslo:variable>
+  <xslo:variable name="chronological_subdivision_subfield">y</xslo:variable>
+  <xslo:variable name="geographic_subdivision_subfield">z</xslo:variable>
+  <xslo:template mode="index_subject_thesaurus" match="marc:controlfield[@tag='008']">
+    <xslo:variable name="thesaurus_code1" select="substring(., 12, 1)"/>
+    <xslo:variable name="full_thesaurus_code">
+      <xslo:choose>
+        <xslo:when test="$thesaurus_code1 = 'a'">
+          <xslo:text>lcsh</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'b'">
+          <xslo:text>lcac</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'c'">
+          <xslo:text>mesh</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'd'">
+          <xslo:text>nal</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'k'">
+          <xslo:text>cash</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'n'">
+          <xslo:text>notapplicable</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'r'">
+          <xslo:text>aat</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 's'">
+          <xslo:text>sears</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'v'">
+          <xslo:text>rvm</xslo:text>
+        </xslo:when>
+        <xslo:when test="$thesaurus_code1 = 'z'">
+          <xslo:choose>
+            <xslo:when test="//marc:datafield[@tag='040']/marc:subfield[@code='f']">
+              <xslo:value-of select="//marc:datafield[@tag='040']/marc:subfield[@code='f']"/>
+            </xslo:when>
+            <xslo:otherwise>
+              <xslo:text>notdefined</xslo:text>
+            </xslo:otherwise>
+          </xslo:choose>
+        </xslo:when>
+        <xslo:otherwise>
+          <xslo:text>notdefined</xslo:text>
+        </xslo:otherwise>
+      </xslo:choose>
+    </xslo:variable>
+    <z:index name="Subject-heading-thesaurus:w">
+      <xslo:value-of select="$full_thesaurus_code"/>
+    </z:index>
+  </xslo:template>
+  <xslo:template match="*">
+    <z:index name="Any:w Any:p">
+      <xslo:value-of select="."/>
     </z:index>
   </xslo:template>
 </xslo:stylesheet>