]> granicus.if.org Git - docbook-dsssl/commitdiff
Bug #567130: make sure literallayout children don't get lost
authorNorman Walsh <ndw@nwalsh.com>
Mon, 8 Jul 2002 13:44:18 +0000 (13:44 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Mon, 8 Jul 2002 13:44:18 +0000 (13:44 +0000)
xsl/html/html-rtf.xsl
xsl/html/verbatim.xsl

index bfb4cfe011d222f03110f4455d70777f6fd10fba..898a2e545d80b0597d9040af4f8fb43814932858 100644 (file)
   </xsl:if>
 </xsl:template>
 
+<!-- ==================================================================== -->
+<!-- make.verbatim.mode replaces spaces and newlines -->
+
+<xsl:template match="/" mode="make.verbatim.mode">
+  <xsl:apply-templates mode="make.verbatim.mode"/>
+</xsl:template>
+
+<xsl:template match="*" mode="make.verbatim.mode">
+  <xsl:copy>
+    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates mode="make.verbatim.mode"/>
+  </xsl:copy>
+</xsl:template>
+
+<xsl:template match="processing-instruction()|comment()" mode="make.verbatim.mode">
+  <xsl:copy/>
+</xsl:template>
+
+<xsl:template match="text()" mode="make.verbatim.mode">
+  <xsl:variable name="text" select="translate(., ' ', '&#160;')"/>
+
+  <xsl:choose>
+    <xsl:when test="not(contains($text, '&#xA;'))">
+      <xsl:value-of select="$text"/>
+    </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:variable name="len" select="string-length($text)"/>
+
+      <xsl:choose>
+        <xsl:when test="$len = 1">
+          <br/><xsl:text>&#xA;</xsl:text>
+        </xsl:when>
+
+        <xsl:otherwise>
+          <xsl:variable name="half" select="$len div 2"/>
+          <xsl:call-template name="make-verbatim-recursive">
+            <xsl:with-param name="text" select="substring($text, 1, $half)"/>
+          </xsl:call-template>
+          <xsl:call-template name="make-verbatim-recursive">
+            <xsl:with-param name="text"
+                            select="substring($text, ($half + 1), $len)"/>
+          </xsl:call-template>
+       </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="make-verbatim-recursive">
+  <xsl:param name="text" select="''"/>
+
+  <xsl:choose>
+    <xsl:when test="not(contains($text, '&#xA;'))">
+      <xsl:value-of select="$text"/>
+    </xsl:when>
+
+    <xsl:otherwise>
+      <xsl:variable name="len" select="string-length($text)"/>
+
+      <xsl:choose>
+        <xsl:when test="$len = 1">
+          <br/><xsl:text>&#xA;</xsl:text>
+        </xsl:when>
+
+        <xsl:otherwise>
+         <xsl:variable name="half" select="$len div 2"/>
+          <xsl:call-template name="make-verbatim-recursive">
+           <xsl:with-param name="text" select="substring($text, 1, $half)"/>
+         </xsl:call-template>
+         <xsl:call-template name="make-verbatim-recursive">
+           <xsl:with-param name="text"
+                           select="substring($text, ($half + 1), $len)"/>
+         </xsl:call-template>
+       </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <!-- ==================================================================== -->
 
 </xsl:stylesheet>
index e638ce36570260d27098df3d992cabfbff91fd03..02282d152ae4403f1695fecd7226e9e720252031 100644 (file)
@@ -3,7 +3,8 @@
                 xmlns:sverb="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Verbatim"
                 xmlns:xverb="com.nwalsh.xalan.Verbatim"
                 xmlns:lxslt="http://xml.apache.org/xslt"
-                exclude-result-prefixes="sverb xverb lxslt"
+                xmlns:exsl="http://exslt.org/common"
+                exclude-result-prefixes="sverb xverb lxslt exsl"
                 version='1.0'>
 
 <!-- ********************************************************************
             <div class="{name(.)}">
               <p>
                 <xsl:call-template name="number.rtf.lines">
-                  <xsl:with-param name="rtf">
-                    <xsl:call-template name="make-verbatim">
-                      <xsl:with-param name="text" select="translate($rtf,' ','&#160;')"/>
-                    </xsl:call-template>
-                  </xsl:with-param>
+                  <xsl:with-param name="rtf" select="$rtf"/>
                 </xsl:call-template>
               </p>
             </div>
             <div class="{name(.)}">
               <p>
                 <xsl:call-template name="make-verbatim">
-                  <xsl:with-param name="text" select="translate($rtf,' ','&#160;')"/>
+                  <xsl:with-param name="rtf" select="$rtf"/>
                 </xsl:call-template>
               </p>
             </div>
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="literallayout[not(@class)
-                                   or @class != 'monospaced']//text()">
-  <xsl:call-template name="make-verbatim">
-    <xsl:with-param name="text" select="translate(.,' ','&#160;')"/>
-  </xsl:call-template>
-</xsl:template>
-
 <xsl:template match="address">
   <xsl:param name="suppress-numbers" select="'0'"/>
 
     <xsl:otherwise>
       <div class="{name(.)}">
         <p>
-          <xsl:apply-templates/>
+          <xsl:call-template name="make-verbatim">
+            <xsl:with-param name="rtf" select="$rtf"/>
+          </xsl:call-template>
         </p>
       </div>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
 
-<xsl:template match="address//text()">
-  <xsl:call-template name="make-verbatim">
-    <xsl:with-param name="text" select="translate(.,' ','&#160;')"/>
-  </xsl:call-template>
-</xsl:template>
-
 <xsl:template name="make-verbatim">
-  <xsl:param name="text" select="''"/>
+  <xsl:param name="rtf"/>
 
-  <xsl:call-template name="make-verbatim-recursive">
-    <xsl:with-param name="text" select="translate($text, ' ', '&#160;')"/>
-  </xsl:call-template>
-</xsl:template>
-
-<xsl:template name="make-verbatim-recursive">
-  <xsl:param name="text" select="''"/>
+  <!-- I want to make this RTF verbatim. There are two possibilities: either
+       I have access to the exsl:node-set extension function and I can "do it right"
+       or I have to rely on CSS. -->
 
   <xsl:choose>
-    <xsl:when test="not(contains($text, '&#xA;'))">
-      <xsl:value-of select="$text"/>
+    <xsl:when test="function-available('exsl:node-set')">
+      <xsl:apply-templates select="exsl:node-set($rtf)" mode="make.verbatim.mode"/>
     </xsl:when>
-
     <xsl:otherwise>
-      <xsl:variable name="len" select="string-length($text)"/>
-
-      <xsl:choose>
-        <xsl:when test="$len = 1">
-          <br/><xsl:text>&#xA;</xsl:text>
-        </xsl:when>
-
-        <xsl:otherwise>
-         <xsl:variable name="half" select="$len div 2"/>
-         <xsl:call-template name="make-verbatim-recursive">
-           <xsl:with-param name="text" select="substring($text, 1, $half)"/>
-         </xsl:call-template>
-         <xsl:call-template name="make-verbatim-recursive">
-           <xsl:with-param name="text"
-                           select="substring($text, ($half + 1), $len)"/>
-         </xsl:call-template>
-       </xsl:otherwise>
-      </xsl:choose>
+      <span style="white-space: pre;">
+        <xsl:copy-of select="$rtf"/>
+      </span>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>