I have added the templates to the pdf.xsl file I have been using and deleted the call to fop-preprocess.rex. When I run the doc2fo and the fo2pdf steps I get what appears to be the same result as when using the fop-preprocess script! Here <https://www.dropbox.com/s/oqx1wrddr75opk2/rexxref.zip?dl=0> is a link to a zipped version in my Dropbox. I will proceed to update my package and documentation and should have something available soon...

Gil

On 2/23/2020 12:06 PM, Gil Barmwater wrote:

Wow! I had suspected it might be possible to accomplish the blank line removal by modifying the stylesheet template for the programlisting element but never got around to exploring what would be required (and learning a lot more XSLT). I will add this to the pdf.xsl file and give it a go.

Gil

On 2/23/2020 11:06 AM, Erich Steinböck wrote:
Removal of unwanted leading/trailing whitespace from a DocBook <programlisting> element with a "fop preprocessing" script was just my bad hack and should be abandoned.

Please add the following code to the xsl style sheet - this should take care of what we want.  The script invocation should be removed.

~~~
<!-- strip leading and trailing whitespace from programlisting
     see https://lists.oasis-open.org/archives/docbook-apps/200304/msg00334.html
-->
<xsl:template match="programlisting/text()">
  <xsl:variable name="before" select="preceding-sibling::node()"/>
  <xsl:variable name="after" select="following-sibling::node()"/>

  <xsl:variable name="conts" select="."/>

  <xsl:variable name="contsl">
    <xsl:choose>
      <xsl:when test="count($before) = 0">
        <xsl:call-template name="remove-lf-left">
          <xsl:with-param name="astr" select="$conts"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$conts"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="contslr">
    <xsl:choose>
      <xsl:when test="count($after) = 0">
        <xsl:call-template name="remove-ws-right">
          <xsl:with-param name="astr" select="$contsl"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$contsl"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:value-of select="$contslr"/>

</xsl:template>


<!-- eats linefeeds from the left -->
<xsl:template name="remove-lf-left">
  <xsl:param name="astr"/>

  <xsl:choose>
    <xsl:when test="starts-with($astr,'&#xA;') or
                    starts-with($astr,'&#xD;')">
      <xsl:call-template name="remove-lf-left">
        <xsl:with-param name="astr" select="substring($astr, 2)"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$astr"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- eats whitespace from the right -->
<xsl:template name="remove-ws-right">
  <xsl:param name="astr"/>

  <xsl:variable name="last-char">
    <xsl:value-of select="substring($astr, string-length($astr), 1)"/>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="($last-char = '&#xA;') or
                    ($last-char = '&#xD;') or
                    ($last-char = '&#x20;') or
                    ($last-char = '&#x9;')">
      <xsl:call-template name="remove-ws-right">
        <xsl:with-param name="astr"
          select="substring($astr, 1, string-length($astr) - 1)"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$astr"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
~~~

The reason why I didn't just go through all our doc XML's and remove unwanted whitespace from <programlisting>'s, is that it not only would have been a lot of work, but it also would make the examples more difficult to read or copy/paste (for the developer, not the user) as the <programlisting> and CDATA markup would have to be all on the same line as the first line of the example.  I had changed a few examples like this, but then didn't like it at all.

This still leaves us with quite a bit of unwanted whitespace from our <indexterm>'s, but that's another story.


_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel
--
Gil Barmwater


_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

--
Gil Barmwater

_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to