]> granicus.if.org Git - docbook-dsssl/commitdiff
Move the stripns code to a common location; update @fileref and @entityref attributes...
authorNorman Walsh <ndw@nwalsh.com>
Thu, 6 Oct 2005 16:27:40 +0000 (16:27 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Thu, 6 Oct 2005 16:27:40 +0000 (16:27 +0000)
xsl/common/stripns.xsl [new file with mode: 0644]
xsl/fo/docbook.xsl
xsl/html/docbook.xsl

diff --git a/xsl/common/stripns.xsl b/xsl/common/stripns.xsl
new file mode 100644 (file)
index 0000000..e813be4
--- /dev/null
@@ -0,0 +1,124 @@
+<?xml version='1.0'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+               xmlns:ng="http://docbook.org/docbook-ng"
+               xmlns:db="http://docbook.org/ns/docbook"
+                xmlns:saxon="http://icl.com/saxon"
+                exclude-result-prefixes="db ng saxon"
+                version='1.0'>
+
+<xsl:template match="*" mode="stripNS">
+  <xsl:choose>
+    <xsl:when test="self::ng:* or self::db:*">
+      <xsl:element name="{local-name(.)}">
+        <xsl:copy-of select="@*"/>
+        <xsl:apply-templates mode="stripNS"/>
+      </xsl:element>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy>
+        <xsl:copy-of select="@*"/>
+        <xsl:apply-templates mode="stripNS"/>
+      </xsl:copy>
+    </xsl:otherwise>
+  </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="ng:textdata|db:textdata
+                    |ng:imagedata|db:imagedata
+                    |ng:videodata|db:videodata
+                    |ng:audiodata|db:audiodata" mode="stripNS">
+  <xsl:element name="{local-name(.)}">
+    <xsl:copy-of select="@*[name(.) != 'fileref' and name(.) != 'entityref']"/>
+
+    <xsl:choose>
+      <xsl:when test="@fileref
+                     and not(contains(@fileref,':'))
+                     and not(starts-with(@fileref,'/'))
+                     and function-available('saxon:systemId')">
+       <xsl:attribute name="fileref">
+         <xsl:call-template name="systemIdToBaseURI">
+           <xsl:with-param name="systemId">
+             <xsl:choose>
+               <!-- file: seems to confuse some processors. -->
+               <xsl:when test="starts-with(saxon:systemId(), 'file:')">
+                 <xsl:value-of select="substring-after(saxon:systemId(),
+                                                       'file:')"/>
+               </xsl:when>
+               <xsl:otherwise>
+                 <xsl:value-of select="saxon:systemId()"/>
+               </xsl:otherwise>
+             </xsl:choose>
+           </xsl:with-param>
+         </xsl:call-template>
+         <xsl:value-of select="@fileref"/>
+       </xsl:attribute>
+      </xsl:when>
+      <xsl:otherwise>
+       <xsl:attribute name="fileref">
+         <xsl:value-of select="@fileref"/>
+       </xsl:attribute>
+      </xsl:otherwise>
+    </xsl:choose>
+
+    <xsl:choose>
+      <xsl:when test="@entityref">
+       <xsl:attribute name="fileref">
+         <xsl:value-of select="unparsed-entity-uri(@entityref)"/>
+       </xsl:attribute>
+      </xsl:when>
+    </xsl:choose>
+
+    <xsl:apply-templates mode="stripNS"/>
+  </xsl:element>
+</xsl:template>
+
+<xsl:template name="systemIdToBaseURI">
+  <xsl:param name="systemId" select="''"/>
+  <xsl:if test="contains($systemId,'/')">
+    <xsl:value-of select="substring-before($systemId,'/')"/>
+    <xsl:text>/</xsl:text>
+    <xsl:call-template name="systemIdToBaseURI">
+      <xsl:with-param name="systemId"
+                     select="substring-after($systemId,'/')"/>
+    </xsl:call-template>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="comment()|processing-instruction()|text()" mode="stripNS">
+  <xsl:copy/>
+</xsl:template>
+
+</xsl:stylesheet>
index 020a0410436f99648507522faf414714623ab4e8..752d1a18fd36f301b368915dcd6f229e749d016b 100644 (file)
@@ -73,6 +73,7 @@
 <xsl:include href="ebnf.xsl"/>
 <xsl:include href="docbookng.xsl"/>
 <xsl:include href="../html/chunker.xsl"/>
+<xsl:include href="../common/stripns.xsl"/>
 
 <xsl:include href="fop.xsl"/>
 <xsl:include href="passivetex.xsl"/>
 
 <!-- ==================================================================== -->
 
-<xsl:template match="*" mode="stripNS">
-  <xsl:choose>
-    <xsl:when test="self::ng:* or self::db:*">
-      <xsl:element name="{local-name(.)}">
-        <xsl:copy-of select="@*"/>
-        <xsl:apply-templates mode="stripNS"/>
-      </xsl:element>
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:copy>
-        <xsl:copy-of select="@*"/>
-        <xsl:apply-templates mode="stripNS"/>
-      </xsl:copy>
-    </xsl:otherwise>
-  </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>
-
-<!-- ==================================================================== -->
-
 </xsl:stylesheet>
index 4e6e347a3592b37ad0b9ffbd765baeddf2483696..38fe26ac362e4d4678aedb77e195c8adb72d4c41 100644 (file)
@@ -71,6 +71,7 @@
 <xsl:include href="html-rtf.xsl"/>
 <xsl:include href="docbookng.xsl"/>
 <xsl:include href="annotations.xsl"/>
+<xsl:include href="../common/stripns.xsl"/>
 
 <xsl:param name="stylesheet.result.type" select="'html'"/>
 <xsl:param name="htmlhelp.output" select="0"/>
@@ -428,60 +429,4 @@ body { background-image: url('</xsl:text>
 
 <!-- ==================================================================== -->
 
-<xsl:template match="*" mode="stripNS">
-  <xsl:choose>
-    <xsl:when test="self::ng:* or self::db:*">
-      <xsl:element name="{local-name(.)}">
-       <xsl:copy-of select="@*"/>
-       <xsl:apply-templates mode="stripNS"/>
-      </xsl:element>
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:copy>
-       <xsl:copy-of select="@*"/>
-       <xsl:apply-templates mode="stripNS"/>
-      </xsl:copy>
-    </xsl:otherwise>
-  </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>
-
-<!-- ==================================================================== -->
-
 </xsl:stylesheet>