]> granicus.if.org Git - docbook-dsssl/commitdiff
'Support' DocBook V5 namespace
authorNorman Walsh <ndw@nwalsh.com>
Fri, 29 Apr 2005 12:13:30 +0000 (12:13 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Fri, 29 Apr 2005 12:13:30 +0000 (12:13 +0000)
xsl/fo/docbook.xsl
xsl/html/docbook.xsl

index ffbeadccc10d10cef45ee2e3f83132c822503bfa..05fc37905fd969b2a26aebd41bd2a4c9646051ad 100644 (file)
@@ -2,7 +2,9 @@
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:exsl="http://exslt.org/common"
                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
-                exclude-result-prefixes="exsl"
+               xmlns:ng="http://docbook.org/docbook-ng"
+               xmlns:db="http://docbook.org/ns/docbook"
+                exclude-result-prefixes="db ng exsl"
                 version='1.0'>
 
 <!-- It is important to use indent="no" here, otherwise verbatim -->
 <xsl:template match="/">
   <xsl:choose>
     <xsl:when test="function-available('exsl:node-set')
-                    and namespace-uri(*[1]) = 'http://docbook.org/docbook-ng'">
-      <!-- Hack! If someone hands us a DocBook NG document, toss the namespace -->
-      <!-- and continue. Someday we may reverse this logic and add the namespace -->
-      <!-- to documents that don't have one. But not before the whole stylesheet -->
-      <!-- has been converted to use namespaces. i.e., don't hold your breath -->
+                   and (*/self::ng:* or */self::db:*)">
+      <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
+          toss the namespace and continue. Someday we'll reverse this logic
+          and add the namespace to documents that don't have one.
+          But not before the whole stylesheet has been converted to use
+          namespaces. i.e., don't hold your breath -->
       <xsl:variable name="nons">
         <xsl:apply-templates mode="stripNS"/>
       </xsl:variable>
 
 <xsl:template match="*" mode="stripNS">
   <xsl:choose>
-    <xsl:when test="namespace-uri(.) = 'http://docbook.org/docbook-ng'">
+    <xsl:when test="self::ng:* or self::db:*">
       <xsl:element name="{local-name(.)}">
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates mode="stripNS"/>
   </xsl:choose>
 </xsl:template>
 
+<xsl:template match="ng:link|db:link" mode="stripNS">
+  <xsl:variable xmlns:xlink="http://www.w3.org/1999/xlink"
+               name="href" select="@xlink:href|@href"/>
+  <xsl:choose>
+    <xsl:when test="$href != '' and not(starts-with($href,'#'))">
+      <ulink url="{$href}">
+       <xsl:for-each select="@*">
+         <xsl:if test="local-name(.) != 'href'">
+           <xsl:copy/>
+         </xsl:if>
+       </xsl:for-each>
+       <xsl:apply-templates mode="stripNS"/>
+      </ulink>
+    </xsl:when>
+    <xsl:when test="$href != '' and starts-with($href,'#')">
+      <link linkend="{substring-after($href,'#')}">
+       <xsl:for-each select="@*">
+         <xsl:if test="local-name(.) != 'href'">
+           <xsl:copy/>
+         </xsl:if>
+       </xsl:for-each>
+       <xsl:apply-templates mode="stripNS"/>
+      </link>
+    </xsl:when>
+    <xsl:otherwise>
+      <link>
+       <xsl:copy-of select="@*"/>
+       <xsl:apply-templates mode="stripNS"/>
+      </link>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
   <xsl:copy/>
 </xsl:template>
index 46427aea8ab01f6fb46d082b80841d3c7d7c3c58..43d93444c65b0595384cf2a5d9ec7d5bd0ebeed5 100644 (file)
@@ -1,8 +1,9 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-               xmlns:db="http://docbook.org/docbook-ng"
+               xmlns:ng="http://docbook.org/docbook-ng"
+               xmlns:db="http://docbook.org/ns/docbook"
                 xmlns:exsl="http://exslt.org/common"
-                exclude-result-prefixes="db exsl"
+                exclude-result-prefixes="db ng exsl"
                 version='1.0'>
 
 <xsl:output method="html"
@@ -292,12 +293,13 @@ body { background-image: url('</xsl:text>
 <xsl:template match="/">
   <xsl:choose>
     <xsl:when test="function-available('exsl:node-set')
-                    and namespace-uri(*[1]) = 'http://docbook.org/docbook-ng'">
-      <!-- Hack! If someone hands us a DocBook NG document, toss the namespace -->
-      <!-- and continue. Someday we may reverse this logic and add the namespace -->
-      <!-- to documents that don't have one. But not before the whole stylesheet -->
-      <!-- has been converted to use namespaces. i.e., don't hold your breath -->
-      <xsl:message>Stripping NS from DocBook-NG document.</xsl:message>
+                   and (*/self::ng:* or */self::db:*)">
+      <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
+          toss the namespace and continue. Someday we'll reverse this logic
+          and add the namespace to documents that don't have one.
+          But not before the whole stylesheet has been converted to use
+          namespaces. i.e., don't hold your breath -->
+      <xsl:message>Stripping NS from DocBook 5/NG document.</xsl:message>
       <xsl:variable name="nons">
        <xsl:apply-templates mode="stripNS"/>
       </xsl:variable>
@@ -398,7 +400,7 @@ body { background-image: url('</xsl:text>
 
 <xsl:template match="*" mode="stripNS">
   <xsl:choose>
-    <xsl:when test="namespace-uri(.) = 'http://docbook.org/docbook-ng'">
+    <xsl:when test="self::ng:* or self::db:*">
       <xsl:element name="{local-name(.)}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates mode="stripNS"/>
@@ -413,7 +415,7 @@ body { background-image: url('</xsl:text>
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="db:link" mode="stripNS">
+<xsl:template match="ng:link|db:link" mode="stripNS">
   <xsl:variable xmlns:xlink="http://www.w3.org/1999/xlink"
                name="href" select="@xlink:href|@href"/>
   <xsl:choose>