]> granicus.if.org Git - docbook-dsssl/commitdiff
Added html.cleanup parameter; if non-zero, do some post-processing of RTFs to improve...
authorNorman Walsh <ndw@nwalsh.com>
Mon, 28 Jan 2002 16:15:09 +0000 (16:15 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Mon, 28 Jan 2002 16:15:09 +0000 (16:15 +0000)
xsl/html/block.xsl
xsl/html/footnote.xsl
xsl/html/html-rtf.xsl [new file with mode: 0644]
xsl/html/param.ent
xsl/html/param.xweb
xsl/params/html.cleanup.xml [new file with mode: 0644]
xsl/params/make.valid.html.xml

index b29a0a66ae52868df3ede5b894830a9c5fcc6f50..21fb16915dc003c1bc1990d791c2acc5d8b601be 100644 (file)
@@ -1,7 +1,5 @@
 <?xml version='1.0'?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-                xmlns:exsl="http://exslt.org/common"
-                exclude-result-prefixes="exsl"
                 version='1.0'>
 
 <!-- ********************************************************************
 <!-- ==================================================================== -->
 
 <xsl:template match="para">
-  <xsl:variable name="the-p">
-  <p>
-    <xsl:if test="position() = 1 and parent::listitem">
-      <xsl:call-template name="anchor">
-        <xsl:with-param name="node" select="parent::listitem"/>
-      </xsl:call-template>
-    </xsl:if>
+  <xsl:variable name="p">
+    <p>
+      <xsl:if test="position() = 1 and parent::listitem">
+        <xsl:call-template name="anchor">
+          <xsl:with-param name="node" select="parent::listitem"/>
+        </xsl:call-template>
+      </xsl:if>
 
-    <xsl:call-template name="anchor"/>
-    <xsl:apply-templates/>
-  </p>
+      <xsl:call-template name="anchor"/>
+      <xsl:apply-templates/>
+    </p>
   </xsl:variable>
 
-  <xsl:copy-of select="$the-p"/>
-<!--
-  <xsl:apply-templates select="exsl:node-set($the-p)" mode="unwrap.p"/>
--->
+  <xsl:choose>
+    <xsl:when test="$html.cleanup != 0">
+      <xsl:call-template name="unwrap.p">
+        <xsl:with-param name="p" select="$p"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy-of select="$p"/>
+    </xsl:otherwise>
+  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="simpara">
index 4cb169c672e02915629583e9424c069af88ed256..c81ef6f51118760a4ce9e7be31056eb95437d8cd 100644 (file)
 
 <!-- ==================================================================== -->
 
-<xsl:template match="para|simpara" mode="footnote.body">
-  <!-- this only works if the first thing in a footnote is a para, -->
-  <!-- which is ok, because it usually is. -->
-  <xsl:variable name="name">
-    <xsl:text>ftn.</xsl:text>
-    <xsl:call-template name="object.id">
-      <xsl:with-param name="object" select="ancestor::footnote"/>
-    </xsl:call-template>
-  </xsl:variable>
-  <xsl:variable name="href">
-    <xsl:text>#</xsl:text>
-    <xsl:call-template name="object.id">
-      <xsl:with-param name="object" select="ancestor::footnote"/>
-    </xsl:call-template>
-  </xsl:variable>
-  <p>
-    <sup>
-      <xsl:text>[</xsl:text>
-      <a name="{$name}" href="{$href}">
-        <xsl:apply-templates select="ancestor::footnote"
-                             mode="footnote.number"/>
-      </a>
-      <xsl:text>] </xsl:text>
-    </sup>
-    <xsl:apply-templates/>
-  </p>
-</xsl:template>
-
-<xsl:template match="*" mode="footnote.body">
+<xsl:template match="*" mode="footnote.body.number">
   <xsl:variable name="name">
     <xsl:text>ftn.</xsl:text>
     <xsl:call-template name="object.id">
   <xsl:variable name="html">
     <xsl:apply-templates select="."/>
   </xsl:variable>
+
   <xsl:variable name="html-nodes" select="exsl:node-set($html)"/>
 
   <xsl:choose>
 
 <xsl:template match="footnote" mode="process.footnote.mode">
   <xsl:choose>
-    <xsl:when test="function-available('exsl:node-set')">
+    <xsl:when test="$html.cleanup != 0 and function-available('exsl:node-set')">
       <div class="{name(.)}">
-        <xsl:apply-templates select="*[1]" mode="footnote.body"/>
+        <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
         <xsl:apply-templates select="*[position() &gt; 1]"/>
       </div>
     </xsl:when>
 
 <xsl:template match="footnote" mode="table.footnote.mode">
   <xsl:choose>
-    <xsl:when test="function-available('exsl:node-set')">
+    <xsl:when test="$html.cleanup != 0 and function-available('exsl:node-set')">
       <div class="{name(.)}">
-        <xsl:apply-templates select="*[1]" mode="footnote.body"/>
+        <xsl:apply-templates select="*[1]" mode="footnote.body.number"/>
         <xsl:apply-templates select="*[position() &gt; 1]"/>
       </div>
     </xsl:when>
diff --git a/xsl/html/html-rtf.xsl b/xsl/html/html-rtf.xsl
new file mode 100644 (file)
index 0000000..8fa7bcd
--- /dev/null
@@ -0,0 +1,188 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:exsl="http://exslt.org/common"
+                xmlns:set="http://exslt.org/sets"
+                exclude-result-prefixes="exsl set"
+                version="1.0">
+
+<!-- This module contains templates that match against HTML nodes. It is used
+     to post-process result tree fragments for some sorts of cleanup.
+     These templates can only ever be fired by a processor that supports
+     exslt:node-set(). -->
+
+<!-- ==================================================================== -->
+
+<!-- insert.html.p mode templates insert a particular RTF at the beginning
+     of the first paragraph in the primary RTF. -->
+
+<xsl:template match="/" mode="insert.html.p">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:apply-templates mode="insert.html.p">
+    <xsl:with-param name="mark" select="$mark"/>
+  </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="*" mode="insert.html.p">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="insert.html.p">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="p" mode="insert.html.p">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:if test="not(preceding::p)">
+      <xsl:copy-of select="$mark"/>
+    </xsl:if>
+    <xsl:apply-templates mode="insert.html.p">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.p">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy/>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<!-- insert.html.text mode templates insert a particular RTF at the beginning
+     of the first text-node in the primary RTF. -->
+
+<xsl:template match="/" mode="insert.html.text">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:apply-templates mode="insert.html.text">
+    <xsl:with-param name="mark" select="$mark"/>
+  </xsl:apply-templates>
+</xsl:template>
+
+<xsl:template match="*" mode="insert.html.text">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="insert.html.text">
+      <xsl:with-param name="mark" select="$mark"/>
+    </xsl:apply-templates>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="text()|processing-instruction()|comment()" mode="insert.html.text">
+  <xsl:param name="mark" select="'?'"/>
+
+  <xsl:if test="not(preceding::text())">
+    <xsl:copy-of select="$mark"/>
+  </xsl:if>
+
+  <xsl:copy/>
+</xsl:template>
+
+<xsl:template match="processing-instruction()|comment()" mode="insert.html.text">
+  <xsl:param name="mark" select="'?'"/>
+  <xsl:copy/>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<!-- unwrap.p mode templates remove blocks from HTML p elements (and
+     other places where blocks aren't allowed) -->
+
+<xsl:template name="unwrap.p">
+  <xsl:param name="p"/>
+  <xsl:choose>
+    <xsl:when test="function-available('exsl:node-set')
+                    and function-available('set:leading')
+                    and function-available('set:trailing')">
+      <xsl:apply-templates select="exsl:node-set($p)" mode="unwrap.p"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy-of select="$p"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="p" mode="unwrap.p">
+  <xsl:variable name="blocks" select="div|p|blockquote|table"/>
+
+  <xsl:choose>
+    <xsl:when test="$blocks">
+      <xsl:call-template name="unwrap.nodes">
+        <xsl:with-param name="wrap" select="."/>
+        <xsl:with-param name="first" select="1"/>
+        <xsl:with-param name="nodes" select="node()"/>
+        <xsl:with-param name="blocks" select="$blocks"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:copy>
+        <xsl:copy-of select="@*"/>
+        <xsl:apply-templates mode="unwrap.p"/>
+      </xsl:copy>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="*" mode="unwrap.p">
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="unwrap.p"/>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="text()|processing-instruction()|comment()" mode="unwrap.p">
+  <xsl:copy/>
+</xsl:template>
+
+<xsl:template name="unwrap.nodes">
+  <xsl:param name="wrap" select="."/>
+  <xsl:param name="first" select="0"/>
+  <xsl:param name="nodes"/>
+  <xsl:param name="blocks"/>
+  <xsl:variable name="block" select="$blocks[1]"/>
+
+  <xsl:choose>
+    <xsl:when test="$blocks">
+      <xsl:variable name="leading" select="set:leading($nodes,$blocks)"/>
+      <xsl:variable name="trailing" select="set:trailing($nodes,$blocks)"/>
+
+      <xsl:element name="{local-name($wrap)}" namespace="{namespace-uri($wrap)}">
+        <xsl:for-each select="$wrap/@*">
+          <xsl:if test="$first != 0 or local-name(.) != 'id'">
+            <xsl:copy/>
+          </xsl:if>
+        </xsl:for-each>
+        <xsl:apply-templates select="$leading" mode="unwrap.p"/>
+      </xsl:element>
+
+      <xsl:apply-templates select="$block" mode="unwrap.p"/>
+
+      <xsl:if test="$trailing">
+        <xsl:call-template name="unwrap.nodes">
+          <xsl:with-param name="wrap" select="$wrap"/>
+          <xsl:with-param name="nodes" select="$trailing"/>
+          <xsl:with-param name="blocks" select="$blocks[position() &gt; 1]"/>
+        </xsl:call-template>
+      </xsl:if>
+    </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:element name="{local-name($wrap)}" namespace="{namespace-uri($wrap)}">
+        <xsl:for-each select="$wrap/@*">
+          <xsl:if test="$first != 0 or local-name(.) != 'id'">
+            <xsl:copy/>
+          </xsl:if>
+        </xsl:for-each>
+        <xsl:apply-templates select="$nodes" mode="unwrap.p"/>
+      </xsl:element>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+</xsl:stylesheet>
index 91692192f0bcad1b4ba63af7de473bc1572e5fd7..4adf04ea05fc4ad33e38b71b37ea849424c22b11 100644 (file)
@@ -56,6 +56,7 @@
 <!ENTITY glossterm.auto.link SYSTEM "../params/glossterm.auto.link.xml">
 <!ENTITY graphic.default.extension SYSTEM "../params/graphic.default.extension.xml">
 <!ENTITY html.base SYSTEM "../params/html.base.xml">
+<!ENTITY html.cleanup SYSTEM "../params/html.cleanup.xml">
 <!ENTITY html.ext SYSTEM "../params/html.ext.xml">
 <!ENTITY html.longdesc SYSTEM "../params/html.longdesc.xml">
 <!ENTITY html.longdesc.link SYSTEM "../params/html.longdesc.link.xml">
index 95ecaf147c17876cae811609a99f805e817a5d8a..5a38468862ef1015fc2cbdc27145b81c84c47274 100644 (file)
@@ -149,6 +149,7 @@ to be incomplete. Don't forget to read the source, too :-)</para>
 &html.longdesc;
 &html.longdesc.link;
 &make.valid.html;
+&html.cleanup;
 </reference>
 
 <reference><title>XSLT Processing</title>
@@ -340,6 +341,7 @@ around all these parameters.</para>
 <src:fragref linkend="glossterm.auto.link.frag"/>
 <src:fragref linkend="graphic.default.extension.frag"/>
 <src:fragref linkend="html.base.frag"/>
+<src:fragref linkend="html.cleanup.frag"/>
 <src:fragref linkend="html.ext.frag"/>
 <src:fragref linkend="html.longdesc.frag"/>
 <src:fragref linkend="html.longdesc.link.frag"/>
diff --git a/xsl/params/html.cleanup.xml b/xsl/params/html.cleanup.xml
new file mode 100644 (file)
index 0000000..43fa6b4
--- /dev/null
@@ -0,0 +1,29 @@
+<refentry id="html.cleanup">
+<refmeta>
+<refentrytitle>html.cleanup</refentrytitle>
+<refmiscinfo role="type">boolean</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>html.cleanup</refname>
+<refpurpose>Attempt to clean up the resulting HTML?</refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+<src:fragment id='html.cleanup.frag'>
+<xsl:param name="html.cleanup" select="1"/>
+</src:fragment>
+</refsynopsisdiv>
+
+<refsect1><title>Description</title>
+
+<para>If non-zero, and if the <ulink url="http://www.exslt.org/">EXSLT</ulink>
+extensions are supported by your processor, the resulting HTML will be
+<quote>cleaned up</quote>. This improves the chances that the
+resulting HTML will be valid. It may also improve the formatting of
+some elements.</para>
+
+<para>This parameter is different from <parameter>make.valid.html</parameter>
+because it uses extension functions to manipulate result-tree-fragments.</para>
+
+</refsect1>
+</refentry>
index e44e9034a953b66c08fc81107ae30fec7909133b..d73a1881a410595e89f4d43d70bcc9b1f133d393 100644 (file)
@@ -21,5 +21,10 @@ extra effort to ensure that the resulting HTML is valid. This may mean that some
 <sgmltag>para</sgmltag> tags are translated into HTML <sgmltag>div</sgmltag>s or
 that other substitutions occur.</para>
 
+<para>This parameter is different from <parameter>html.cleanup</parameter>
+because it changes the resulting markup; it does not use extension functions
+to manipulate result-tree-fragments and is therefore applicable to any
+XSLT processor.</para>
+
 </refsect1>
 </refentry>