<xsl:apply-templates/>
</xsl:template>
-<xsl:template match="para">
- <xsl:text>.PP </xsl:text>
+<xsl:template name="mixed-block">
+ <!-- jump through a few hoops to deal with mixed-content blocks, so that -->
+ <!-- we don't end up munging verbatim environments or lists and so that we -->
+ <!-- don't gobble up whitespace when we shouldn't -->
<xsl:for-each select="node()">
<xsl:choose>
- <xsl:when test="self::literallayout|self::informaltable|self::screen|
- self::programlisting|self::itemizedlist|
- self::orderedlist|self::variablelist|self::simplelist">
- <xsl:text> </xsl:text>
+ <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. -->
+
+ <!-- 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> </xsl:text>
<xsl:apply-templates select="."/>
+ <!-- we don't need an extra line break after verbatim environments
+ <xsl:text> </xsl:text>
+ -->
+ </xsl:when>
+ <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> </xsl:text>
+ <xsl:apply-templates select="."/>
+ <!-- we don't need an extra line break after lists
+ <xsl:text> </xsl:text>
+ -->
</xsl:when>
<xsl:when test="self::text()">
- <xsl:if test="starts-with(translate(.,' ',' '), ' ') and
- preceding-sibling::node()[name(.)!='']">
- <xsl:text> </xsl:text>
+ <!-- Check to see if this is a text node. -->
+
+ <!-- If so, take any multiple whitespace at the beginning or end of -->
+ <!-- it, and replace it with a space plus a linebreak. -->
+
+ <!-- This hack results in some ugliness in the generated roff -->
+ <!-- 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(.,'	 ',' '),
+ ' ') and preceding-sibling::node()[name(.)!='']">
+ <xsl:text> </xsl:text>
</xsl:if>
<xsl:variable name="content">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:value-of select="normalize-space($content)"/>
<xsl:if
- test="translate(substring(., string-length(.), 1),' ',' ') = ' ' and
- following-sibling::node()[name(.)!='']">
- <xsl:text> </xsl:text>
+ test="translate(substring(., string-length(.), 1),'	 ',' ')
+ = ' ' and following-sibling::node()[name(.)!='']">
+ <xsl:text> </xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
- <xsl:variable name="content">
+ <!-- At this point, we know that this node is not a verbatim -->
+ <!-- environment, list, or text node; so we can safely -->
+ <!-- normailize-space() it. -->
+ <xsl:variable name="content">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:value-of select="normalize-space($content)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
+</xsl:template>
+
+<xsl:template match="para">
+ <xsl:text>.PP </xsl:text>
+ <xsl:call-template name="mixed-block"/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:apply-templates/>
</xsl:variable>
<xsl:value-of select="normalize-space($content)"/>
- <xsl:text>
-</xsl:text>
+ <xsl:text> </xsl:text>
</xsl:template>
-
<xsl:template match="refentry">
<xsl:text>''</xsl:text>
</xsl:template>
-<xsl:template match="programlisting|literallayout">
+<xsl:template match="address|literallayout|programlisting|screen|synopsis">
+ <!-- Yes, address and synopsis are verbatim environments. -->
+
+ <xsl:choose>
+ <!-- Check to see if this vertbatim item is within a parent element that -->
+ <!-- allows mixed content. -->
+
+ <!-- If it is within a mixed-content parent, then a line break is -->
+ <!-- already added before it by the mixed-block template, so we don't -->
+ <!-- need to add one here. -->
+
+ <!-- If it is not within a mixed-content parent, then we need to add a -->
+ <!-- line break before it. -->
+ <xsl:when test="parent::caption|parent::entry|parent::para|
+ parent::td|parent::th" /> <!-- do nothing -->
+ <xsl:otherwise>
+ <xsl:text> </xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
<xsl:text>.nf </xsl:text>
<xsl:apply-templates/>
+ <xsl:text> </xsl:text>
<xsl:text>.fi </xsl:text>
</xsl:template>
<xsl:template match="para[ancestor::listitem or ancestor::step]|
simpara[ancestor::listitem or ancestor::step]|
remark[ancestor::listitem or ancestor::step]">
- <xsl:for-each select="node()">
- <xsl:choose>
- <xsl:when test="self::literallayout|self::screen|self::programlisting|
- self::itemizedlist|self::orderedlist|self::variablelist|
- self::simplelist">
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="."/>
- </xsl:when>
- <xsl:when test="self::text()">
- <xsl:if test="starts-with(translate(.,' ',' '), ' ') and
- preceding-sibling::node()[name(.)!='']">
- <xsl:text> </xsl:text>
- </xsl:if>
- <xsl:variable name="content">
- <xsl:apply-templates select="."/>
- </xsl:variable>
- <xsl:value-of select="normalize-space($content)"/>
- <xsl:if
- test="translate(substring(., string-length(.), 1),' ',' ') = ' '
- and following-sibling::node()[name(.)!='']">
- <xsl:text> </xsl:text>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="content">
- <xsl:apply-templates select="."/>
- </xsl:variable>
- <xsl:value-of select="normalize-space($content)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
+ <xsl:call-template name="mixed-block"/>
<xsl:text> </xsl:text>
<xsl:if test="following-sibling::para or
</xsl:if>
</xsl:template>
+<xsl:template match="simpara[ancestor::listitem or ancestor::step]|
+ remark[ancestor::listitem or ancestor::step]">
+ <xsl:variable name="content">
+ <xsl:apply-templates/>
+ </xsl:variable>
+ <xsl:value-of select="normalize-space($content)"/>
+ <xsl:text> </xsl:text>
+ <xsl:if test="following-sibling::para or
+ following-sibling::simpara or
+ following-sibling::remark">
+ <!-- Make sure multiple paragraphs within a list item don't -->
+ <!-- merge together. -->
+ <xsl:text> </xsl:text>
+ </xsl:if>
+</xsl:template>
+
<xsl:template match="varlistentry|glossentry">
<xsl:text>.TP </xsl:text>
<xsl:apply-templates/>