]> granicus.if.org Git - docbook-dsssl/commitdiff
Remove duplicated IDs when endterm is used on xref
authorNorman Walsh <ndw@nwalsh.com>
Fri, 17 Jan 2003 13:34:46 +0000 (13:34 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Fri, 17 Jan 2003 13:34:46 +0000 (13:34 +0000)
xsl/fo/xref.xsl
xsl/html/xref.xsl

index ca7f419b9935ef59e66ec61434264090748e9335..4ef561645394d74ab16af643c3ea33fc8e8756e9 100644 (file)
@@ -1,6 +1,8 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
+                xmlns:exsl="http://exslt.org/common"
+                exclude-result-prefixes="exsl"
                 version='1.0'>
 
 <!-- ********************************************************************
   </xsl:if>
 </xsl:template>
 
+<!-- ==================================================================== -->
+
 <xsl:template match="*" mode="endterm">
   <!-- Process the children of the endterm element -->
-  <xsl:apply-templates select="child::node()"/>
+  <xsl:variable name="endterm">
+    <xsl:apply-templates select="child::node()"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="function-available('exsl:node-set')">
+      <xsl:apply-templates select="exsl:node-set($endterm)" mode="remove-ids"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy-of select="$endterm"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="*" mode="remove-ids">
+  <xsl:copy>
+    <xsl:for-each select="@*">
+      <xsl:choose>
+        <xsl:when test="name(.) != 'id'">
+          <xsl:copy/>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:message>removing <xsl:value-of select="name(.)"/></xsl:message>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
+    <xsl:apply-templates mode="remove-ids"/>
+  </xsl:copy>
 </xsl:template>
 
 <!--- ==================================================================== -->
index 8a4862436a77c4d0913b903d2d80bc85138ae553..fee347db7efaefb155883d4961a8a2efa60704be 100644 (file)
@@ -1,7 +1,8 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:suwl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.UnwrapLinks"
-                exclude-result-prefixes="suwl"
+                xmlns:exsl="http://exslt.org/common"
+                exclude-result-prefixes="suwl exsl"
                 version='1.0'>
 
 <!-- ********************************************************************
   </xsl:choose>
 </xsl:template>
 
+<!-- ==================================================================== -->
+
 <xsl:template match="*" mode="endterm">
   <!-- Process the children of the endterm element -->
-  <xsl:apply-templates select="child::node()"/>
+  <xsl:variable name="endterm">
+    <xsl:apply-templates select="child::node()"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="function-available('exsl:node-set')">
+      <xsl:apply-templates select="exsl:node-set($endterm)" mode="remove-ids"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy-of select="$endterm"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="*" mode="remove-ids">
+  <xsl:choose>
+    <!-- handle html or xhtml -->
+    <xsl:when test="local-name(.) = 'a'
+                    and (namespace-uri(.) = ''
+                         or namespace-uri(.) = 'http://www.w3.org/1999/xhtml')">
+      <xsl:choose>
+        <xsl:when test="(@name and count(@*) = 1)
+                        or (@id and count(@*) = 1)
+                        or (@id and @name and count(@*) = 2)">
+          <xsl:message>suppress anchor</xsl:message>
+          <!-- suppress the whole thing -->
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:copy>
+            <xsl:for-each select="@*">
+              <xsl:choose>
+                <xsl:when test="name(.) != 'name' and name(.) != 'id'">
+                  <xsl:copy/>
+                </xsl:when>
+                <xsl:otherwise>
+                  <xsl:message>removing <xsl:value-of select="name(.)"/></xsl:message>
+                </xsl:otherwise>
+              </xsl:choose>
+            </xsl:for-each>
+          </xsl:copy>
+          <xsl:apply-templates mode="remove-ids"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy>
+        <xsl:for-each select="@*">
+          <xsl:choose>
+            <xsl:when test="name(.) != 'id'">
+              <xsl:copy/>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:message>removing <xsl:value-of select="name(.)"/></xsl:message>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:for-each>
+        <xsl:apply-templates mode="remove-ids"/>
+      </xsl:copy>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <!-- ==================================================================== -->