Whitespace Grand Unification: Epilogue (1): If "neighboring" text
authorMichael Smith <xmldoc@users.sourceforge.net>
Sat, 21 May 2005 11:17:23 +0000 (11:17 +0000)
committerMichael Smith <xmldoc@users.sourceforge.net>
Sat, 21 May 2005 11:17:23 +0000 (11:17 +0000)
nodes in mixed content are whitespace-only, leave them unseasoned;
that is, don't add the special sauce.

xsl/manpages/docbook.xsl

index 43e81c470f7e4c0455a0549b3dc3b95b6ccd9351..454d2e20d5ee65d002ffe995737cecaafce7a71f 100644 (file)
       <xsl:when test="self::address|self::literallayout|self::programlisting|
                      self::screen|self::synopsis">
        <!-- Check to see if this node is a verbatim environment. -->
-       <!-- If so, put line breaks before and after it. -->
+       <!-- If so, put a line break before it. -->
        
        <!-- Yes, address and synopsis are vertabim environments. -->
        
        <!-- The code here previously also treated informaltable as a -->
        <!-- verbatim, presumably to support some kludge; I removed it -->
-       <xsl:text> &#10;</xsl:text>
+       <xsl:text>&#10;</xsl:text>
         <xsl:apply-templates select="."/>
        <!-- we don't need an extra line break after verbatim environments
         <xsl:text> &#10;</xsl:text>
       <xsl:when test="self::itemizedlist|self::orderedlist|
                      self::variablelist|self::simplelist">
        <!-- Check to see if this node is a list; if so, -->
-       <!-- put line breaks before and after it. -->
-        <xsl:text> &#10;</xsl:text>
+       <!-- put a line break before it. -->
+        <xsl:text>&#10;</xsl:text>
         <xsl:apply-templates select="."/>
        <!-- we don't need an extra line break after lists
         <xsl:text> &#10;</xsl:text>
        <!-- source. But it ensures the whitespace around text nodes in mixed -->
        <!-- content gets preserved; without the hack, that whitespace -->
        <!-- effectively gets gobbled. -->
-       <xsl:if test="starts-with(translate(.,'&#9;&#10;&#13; ','    '),
-                     ' ') and preceding-sibling::node()[name(.)!='']">
-         <xsl:text> &#10;</xsl:text>
-       </xsl:if>
+
+       <!-- Note the last part of the two tests below; if the node is just -->
+       <!-- space, we just pass it through without doing our special magic -->
+       <!-- on it. -->
+       
+       <!-- There must be a better way to do with this...  -->
         <xsl:variable name="content">
          <xsl:apply-templates select="."/>
        </xsl:variable>
+       <xsl:if
+           test="starts-with(translate(.,'&#9;&#10;&#13; ','    '), ' ')
+                 and preceding-sibling::node()[name(.)!='']
+                 and normalize-space($content) != ''
+                 ">
+         <xsl:text> &#10;</xsl:text>
+       </xsl:if>
        <xsl:value-of select="normalize-space($content)"/>
        <xsl:if
-           test="translate(substring(., string-length(.), 1),'&#x9;&#10;&#13; ','    ')
-                 = ' ' and following-sibling::node()[name(.)!='']">
+           test="translate(substring(., string-length(.), 1),'&#x9;&#10;&#13; ','    ')  = ' '
+                 and following-sibling::node()[name(.)!='']
+                 and normalize-space($content) != ''
+                 ">
          <xsl:text> &#10;</xsl:text>
        </xsl:if>
       </xsl:when>