]> granicus.if.org Git - docbook-dsssl/commitdiff
An index now contains only indexterms within its scope
authorBob Stayton <bobs@sagehill.net>
Thu, 12 Dec 2002 09:29:51 +0000 (09:29 +0000)
committerBob Stayton <bobs@sagehill.net>
Thu, 12 Dec 2002 09:29:51 +0000 (09:29 +0000)
(within its parent element).

xsl/fo/autoidx.xsl

index 5990701cdbaee3f74ad22254a7c935d1085364f6..4cdfeb5e79fbbf2de08d7945e6a1177edd79f04f 100644 (file)
          use="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see)"/>
 
 <xsl:template name="generate-index">
+  <xsl:variable name="scope" select=".." />
   <xsl:variable name="terms"
-                select="//indexterm[count(.|key('letter',
+                select="..//indexterm[count(.|key('letter',
                                                 translate(substring(&primary;, 1, 1),
                                                           &lowercase;,
-                                                          &uppercase;))[1]) = 1
+                                                          &uppercase;))[ancestor::* = $scope][1]) = 1
                                     and not(@class = 'endofrange')]"/>
 
   <xsl:variable name="alphabetical"
       </fo:block>
       <fo:block>
         <xsl:apply-templates select="$others[count(.|key('primary',
-                                     &primary;)[1]) = 1]"
+                                     &primary;)[ancestor::* = $scope][1]) = 1]"
                              mode="index-symbol-div">
+          <xsl:with-param name="scope" select="$scope"/>
           <xsl:sort select="&primary;"/>
         </xsl:apply-templates>
       </fo:block>
     </xsl:if>
     <xsl:apply-templates select="$alphabetical[count(.|key('letter',
-                                 translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"
+                                 translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[ancestor::* = $scope][1]) = 1]"
                          mode="index-div">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="&primary;"/>
     </xsl:apply-templates>
   </fo:block>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-div">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
+  <xsl:variable name="terms" select="key('letter', $key)[ancestor::* = $scope][count(.|key('primary', &primary;)[1]) = 1]"/>
   <fo:block>
     <xsl:if test="contains(concat(&lowercase;, &uppercase;), $key)">
       <fo:block font-size="16pt"
       </fo:block>
     </xsl:if>
     <fo:block>
-      <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
+      <xsl:apply-templates select="$terms"
                            mode="index-primary">
         <xsl:sort select="&primary;"/>
+        <xsl:with-param name="scope" select="$scope"/>
       </xsl:apply-templates>
     </fo:block>
   </fo:block>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-symbol-div">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
 
   <fo:block>
-    <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
+    <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[ancestor::* = $scope][1]) = 1]"
                          mode="index-primary">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="&primary;"/>
     </xsl:apply-templates>
   </fo:block>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-primary">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="&primary;"/>
-  <xsl:variable name="refs" select="key('primary', $key)"/>
+  <xsl:variable name="refs" select="key('primary', $key)[ancestor::* = $scope]"/>
   <fo:block>
     <xsl:value-of select="primary"/>
 
     <xsl:variable name="page-number-citations">
       <xsl:for-each select="$refs[not(see) and not(seealso)]">
-        <xsl:apply-templates select="." mode="reference"/>
+        <xsl:apply-templates select="." mode="reference">
+          <xsl:with-param name="scope" select="$scope"/>
+        </xsl:apply-templates>
       </xsl:for-each>
 
       <xsl:if test="$refs[not(secondary)]/*[self::see]">
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[1])]"
+        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[ancestor::* = $scope][1])]"
                              mode="index-see">
-          <xsl:sort select="see"/>
+           <xsl:with-param name="scope" select="$scope"/>
+           <xsl:sort select="see"/>
         </xsl:apply-templates>
       </xsl:if>
     </xsl:variable>
 
   <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::seealso]">
     <fo:block start-indent="1pc">
-      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[1])]"
+      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[ancestor::* = $scope][1])]"
                            mode="index-seealso">
-        <xsl:sort select="seealso"/>
+         <xsl:with-param name="scope" select="$scope"/>
+         <xsl:sort select="seealso"/>
       </xsl:apply-templates>
-      <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[1]) = 1]"
+      <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[ancestor::* = $scope][1]) = 1]"
                            mode="index-secondary">
-        <xsl:sort select="&secondary;"/>
+       <xsl:with-param name="scope" select="$scope"/>
+       <xsl:sort select="&secondary;"/>
       </xsl:apply-templates>
     </fo:block>
   </xsl:if>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-secondary">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
-  <xsl:variable name="refs" select="key('secondary', $key)"/>
+  <xsl:variable name="refs" select="key('secondary', $key)[ancestor::* = $scope]"/>
   <fo:block>
     <xsl:value-of select="secondary"/>
 
     <xsl:variable name="page-number-citations">
       <xsl:for-each select="$refs[not(see) and not(seealso)]">
-        <xsl:apply-templates select="." mode="reference"/>
+        <xsl:apply-templates select="." mode="reference">
+          <xsl:with-param name="scope" select="$scope"/>
+        </xsl:apply-templates>
       </xsl:for-each>
 
       <xsl:if test="$refs[not(tertiary)]/*[self::see]">
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[1])]"
+        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[ancestor::* = $scope][1])]"
                              mode="index-see">
+          <xsl:with-param name="scope" select="$scope"/>
           <xsl:sort select="see"/>
         </xsl:apply-templates>
       </xsl:if>
 
   <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::seealso]">
     <fo:block start-indent="2pc">
-      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[1])]"
+      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[ancestor::* = $scope][1])]"
                            mode="index-seealso">
-        <xsl:sort select="seealso"/>
+          <xsl:with-param name="scope" select="$scope"/>
+          <xsl:sort select="seealso"/>
       </xsl:apply-templates>
-      <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[1]) = 1]" 
+      <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[ancestor::* = $scope][1]) = 1]" 
                            mode="index-tertiary">
-        <xsl:sort select="&tertiary;"/>
+          <xsl:with-param name="scope" select="$scope"/>
+          <xsl:sort select="&tertiary;"/>
       </xsl:apply-templates>
     </fo:block>
   </xsl:if>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-tertiary">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
-  <xsl:variable name="refs" select="key('tertiary', $key)"/>
+  <xsl:variable name="refs" select="key('tertiary', $key)[ancestor::* = $scope]"/>
   <fo:block>
     <xsl:value-of select="tertiary"/>
 
     <xsl:variable name="page-number-citations">
       <xsl:for-each select="$refs[not(see) and not(seealso)]">
-        <xsl:apply-templates select="." mode="reference"/>
+        <xsl:apply-templates select="." mode="reference">
+          <xsl:with-param name="scope" select="$scope"/>
+        </xsl:apply-templates>
       </xsl:for-each>
 
       <xsl:if test="$refs/see">
-        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
+        <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[ancestor::* = $scope][1])]"
                              mode="index-see">
+          <xsl:with-param name="scope" select="$scope"/>
           <xsl:sort select="see"/>
         </xsl:apply-templates>
       </xsl:if>
 
   <xsl:if test="$refs/seealso">
     <fo:block>
-      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[1])]"
+      <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[ancestor::* = $scope][1])]"
                            mode="index-seealso">
+        <xsl:with-param name="scope" select="$scope"/>
         <xsl:sort select="seealso"/>
       </xsl:apply-templates>
     </fo:block>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="reference">
+  <xsl:param name="scope" select="."/>
   <xsl:param name="separator" select="', '"/>
 
   <xsl:if test="$passivetex.extensions = '0'">
     <xsl:when test="@zone and string(@zone)">
       <xsl:call-template name="reference">
         <xsl:with-param name="zones" select="normalize-space(@zone)"/>
+        <xsl:with-param name="scope" select="$scope"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       </fo:basic-link>
 
       <xsl:if test="key('endofrange', @id)">
-        <xsl:apply-templates select="key('endofrange', @id)[last()]"
+        <xsl:apply-templates select="key('endofrange', @id)[ancestor::* = $scope][last()]"
                              mode="reference">
+          <xsl:with-param name="scope" select="$scope"/>
           <xsl:with-param name="separator" select="'-'"/>
         </xsl:apply-templates>
       </xsl:if>
 </xsl:template>
 
 <xsl:template name="reference">
+  <xsl:param name="scope" select="."/>
   <xsl:param name="zones"/>
   <xsl:choose>
     <xsl:when test="contains($zones, ' ')">
       <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
-      <xsl:variable name="target" select="key('id', $zone)"/>
+      <xsl:variable name="target" select="key('id', $zone)[ancestor::* = $scope]"/>
 
       <xsl:variable name="id">
         <xsl:call-template name="object.id">
-          <xsl:with-param name="object" select="$target[1]"/>
+           <xsl:with-param name="object" select="$target[1]"/>
         </xsl:call-template>
       </xsl:variable>
 
       </xsl:if>
       <xsl:call-template name="reference">
         <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
+        <xsl:with-param name="scope" select="$scope"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
       <xsl:variable name="zone" select="$zones"/>
-      <xsl:variable name="target" select="key('id', $zone)"/>
+      <xsl:variable name="target" select="key('id', $zone)[ancestor::* = $scope]"/>
 
       <xsl:variable name="id">
         <xsl:call-template name="object.id">
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-see">
+   <xsl:param name="scope" select="."/>
    <fo:inline>
      <xsl:text> (</xsl:text>
      <xsl:call-template name="gentext">
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-seealso">
+   <xsl:param name="scope" select="."/>
    <fo:block>
      <xsl:text>(</xsl:text>
      <xsl:call-template name="gentext">
 <!-- ====================================================================== -->
 
 <xsl:template name="generate-index-markup">
-  <xsl:variable name="terms" select="//indexterm[count(.|key('letter',
-                                     translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"/>
+  <xsl:variable name="scope" select=".."/>
+  <xsl:variable name="terms" select="..//indexterm[count(.|key('letter',
+                                     translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[ancestor::* = $scope][1]) = 1]"/>
   <xsl:variable name="alphabetical"
                 select="$terms[contains(concat(&lowercase;, &uppercase;),
                                         substring(&primary;, 1, 1))]"/>
     </xsl:call-template>
     <xsl:text>&lt;/title&gt;&#10;</xsl:text>
     <xsl:apply-templates select="$others[count(.|key('primary',
-                                 &primary;)[1]) = 1]"
+                                 &primary;)[ancestor::* = $scope][1]) = 1]"
                          mode="index-symbol-div-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="&primary;"/>
     </xsl:apply-templates>
     <xsl:text>&lt;/indexdiv&gt;&#10;</xsl:text>
   </xsl:if>
 
   <xsl:apply-templates select="$alphabetical[count(.|key('letter',
-                               translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[1]) = 1]"
+                               translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;))[ancestor::* = $scope][1]) = 1]"
                        mode="index-div-markup">
-    <xsl:sort select="&primary;"/>
+      <xsl:with-param name="scope" select="$scope"/>
+      <xsl:sort select="&primary;"/>
   </xsl:apply-templates>
   <xsl:text>&lt;/index&gt;&#10;</xsl:text>
 </xsl:template>
 
 <xsl:template match="*" mode="index-markup">
+  <xsl:param name="scope" select="."/>
+
   <xsl:text>&lt;</xsl:text>
   <xsl:value-of select="name(.)"/>
   <xsl:text>&gt;&#10;</xsl:text>
-  <xsl:apply-templates mode="index-markup"/>
+  <xsl:apply-templates mode="index-markup">
+    <xsl:with-param name="scope" select="$scope"/>
+  </xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-div-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
   <xsl:text>&#10;&lt;indexdiv&gt;&#10;</xsl:text>
   <xsl:text>&lt;title&gt;</xsl:text>
   <xsl:value-of select="translate($key, &lowercase;, &uppercase;)"/>
   <xsl:text>&lt;/title&gt;&#10;</xsl:text>
 
-  <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
+  <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[ancestor::* = $scope][1]) = 1]"
                        mode="index-primary-markup">
+    <xsl:with-param name="scope" select="$scope"/>
     <xsl:sort select="&primary;"/>
   </xsl:apply-templates>
   <xsl:text>&lt;/indexdiv&gt;&#10;</xsl:text>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-symbol-div-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="translate(substring(&primary;, 1, 1),&lowercase;,&uppercase;)"/>
 
-  <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[1]) = 1]"
+  <xsl:apply-templates select="key('letter', $key)[count(.|key('primary', &primary;)[ancestor::* = $scope][1]) = 1]"
                        mode="index-primary-markup">
+    <xsl:with-param name="scope" select="$scope"/>
     <xsl:sort select="&primary;"/>
   </xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-primary-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="&primary;"/>
-  <xsl:variable name="refs" select="key('primary', $key)"/>
+  <xsl:variable name="refs" select="key('primary', $key)[ancestor::* = $scope]"/>
   <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
 
   <xsl:text>&#10;&lt;indexentry&gt;&#10;</xsl:text>
   <xsl:text>&#10;</xsl:text>
 
   <xsl:for-each select="$pages">
-    <xsl:apply-templates select="." mode="reference-markup"/>
+    <xsl:apply-templates select="." mode="reference-markup">
+      <xsl:with-param name="scope" select="$scope"/>
+    </xsl:apply-templates>
   </xsl:for-each>
 
   <xsl:text>&lt;/primaryie&gt;&#10;</xsl:text>
 
   <xsl:if test="$refs/secondary or $refs[not(secondary)]/*[self::see or self::seealso]">
-    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[1])]"
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &sep;, &sep;, see))[ancestor::* = $scope][1])]"
                          mode="index-see-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="see"/>
     </xsl:apply-templates>
 
-    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[1])]"
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &sep;, &sep;, seealso))[ancestor::* = $scope][1])]"
                          mode="index-seealso-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="seealso"/>
     </xsl:apply-templates>
 
-    <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[1]) = 1]" 
+    <xsl:apply-templates select="$refs[secondary and count(.|key('secondary', concat($key, &sep;, &secondary;))[ancestor::* = $scope][1]) = 1]" 
                          mode="index-secondary-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="&secondary;"/>
     </xsl:apply-templates>
   </xsl:if>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-secondary-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;)"/>
-  <xsl:variable name="refs" select="key('secondary', $key)"/>
+  <xsl:variable name="refs" select="key('secondary', $key)[ancestor::* = $scope]"/>
   <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
 
   <xsl:text>&lt;secondaryie&gt;</xsl:text>
   <xsl:text>&#10;</xsl:text>
 
   <xsl:for-each select="$pages">
-    <xsl:apply-templates select="." mode="reference-markup"/>
+    <xsl:apply-templates select="." mode="reference-markup">
+      <xsl:with-param name="scope" select="$scope"/>
+    </xsl:apply-templates>
   </xsl:for-each>
 
   <xsl:text>&lt;/secondaryie&gt;&#10;</xsl:text>
 
   <xsl:if test="$refs/tertiary or $refs[not(tertiary)]/*[self::see or self::seealso]">
-    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[1])]"
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, see))[ancestor::* = $scope][1])]"
                          mode="index-see-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="see"/>
     </xsl:apply-templates>
-    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[1])]"
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &sep;, seealso))[ancestor::* = $scope][1])]"
                          mode="index-seealso-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="seealso"/>
     </xsl:apply-templates>
-    <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[1]) = 1]" 
+    <xsl:apply-templates select="$refs[tertiary and count(.|key('tertiary', concat($key, &sep;, &tertiary;))[ancestor::* = $scope][1]) = 1]" 
                          mode="index-tertiary-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="&tertiary;"/>
     </xsl:apply-templates>
   </xsl:if>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-tertiary-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:variable name="key" select="concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;)"/>
-  <xsl:variable name="refs" select="key('tertiary', $key)"/>
+  <xsl:variable name="refs" select="key('tertiary', $key)[ancestor::* = $scope]"/>
   <xsl:variable name="pages" select="$refs[not(see) and not(seealso)]"/>
 
   <xsl:text>&lt;tertiaryie&gt;</xsl:text>
   <xsl:text>&#10;</xsl:text>
 
   <xsl:for-each select="$pages">
-    <xsl:apply-templates select="." mode="reference-markup"/>
+    <xsl:apply-templates select="." mode="reference-markup">
+      <xsl:with-param name="scope" select="$scope"/>
+    </xsl:apply-templates>
   </xsl:for-each>
 
   <xsl:text>&lt;/tertiaryie&gt;&#10;</xsl:text>
 
   <xsl:variable name="see" select="$refs/see | $refs/seealso"/>
   <xsl:if test="$see">
-    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[1])]"
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, see))[ancestor::* = $scope][1])]"
                          mode="index-see-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="see"/>
     </xsl:apply-templates>
-    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[1])]"
+    <xsl:apply-templates select="$refs[generate-id() = generate-id(key('see-also', concat(&primary;, &sep;, &secondary;, &sep;, &tertiary;, &sep;, seealso))[ancestor::* = $scope][1])]"
                          mode="index-seealso-markup">
+      <xsl:with-param name="scope" select="$scope"/>
       <xsl:sort select="seealso"/>
     </xsl:apply-templates>
   </xsl:if>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="reference-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:choose>
     <xsl:when test="@zone and string(@zone)">
       <xsl:call-template name="reference-markup">
         <xsl:with-param name="zones" select="normalize-space(@zone)"/>
+        <xsl:with-param name="scope" select="$scope"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
 </xsl:template>
 
 <xsl:template name="reference-markup">
+  <xsl:param name="scope" select="."/>
   <xsl:param name="zones"/>
   <xsl:choose>
     <xsl:when test="contains($zones, ' ')">
       <xsl:variable name="zone" select="substring-before($zones, ' ')"/>
-      <xsl:variable name="target" select="key('id', $zone)"/>
+      <xsl:variable name="target" select="key('id', $zone)[ancestor::* = $scope]"/>
 
       <xsl:variable name="id">
         <xsl:call-template name="object.id">
 
       <xsl:call-template name="reference">
         <xsl:with-param name="zones" select="substring-after($zones, ' ')"/>
+        <xsl:with-param name="scope" select="$scope"/>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-see-markup">
+  <xsl:param name="scope" select="."/>
   <fo:block>
     <xsl:text>&lt;seeie&gt;</xsl:text>
     <xsl:text>&lt;phrase&gt;</xsl:text>
 </xsl:template>
 
 <xsl:template match="indexterm" mode="index-seealso-markup">
+  <xsl:param name="scope" select="."/>
   <fo:block>
     <xsl:text>&lt;seealsoie&gt;</xsl:text>
     <xsl:text>&lt;phrase&gt;</xsl:text>