0

I use docbook to generate documents. The structure of the main document is modular using xinclude for the different modules.

My problem is about verbatim elements(elements with significant whitespaces) which are included into the main document via xinclude.

If I use a literallayout directly in the main document, the output is as expected: whitespaces are preserved.

I want to use an included file which contains a section with a literallayout element. If I generate a document with the included file the output gets stripped of its whitespaces.

Can anyone tell me how to keep the whitespaces in verbatim elements like literallayout or programlisting?

File1.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<section id="someid">
<title>section title</title>
<para>
<literallayout>
This shall show a small picure with '0':
   0
  000
 00000 
</literallayout>
</para>
</section>

If I generate it as standalone document the output is as expected:

    0
   000
  00000 

If I use it as follows: File2.xml:

<?xml version="1.0" encoding="ISO-8859-15"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<book>
<bookinfo>
   ...minimum input here
</bookinfo>
<chapter id="First_Chapter">
    <title>Introduction</title>

    <section id="First_Section">
      <title>literallayout and programlisting in the main xml file</title>

      <para><literallayout>This should look like a triangle built out of the character '0'
   0
  000
 00000
</para>
    </section>

    <xi:include href="File1.xml"
                xmlns:xi="http://www.w3.org/2001/XInclude" />
  </chapter>
</book>

If I generate this document the first section will be as expected (as a pyramid)

but in the section which is included with xinclude all '0' are output on one line 0 000 00000.

Michael B.
  • 54
  • 5

2 Answers2

1

Probable solution

I think found a solution to the problem myself: It should help if the included literallayout elements have the attribute xml:space="preserve" added. This should be the default but it seems that the xinclude somehow "loses" or "replaces" it.

Michael B.
  • 54
  • 5
  • It seems reasonable that XInclude processing strips whitespace by default. The XInclude processor cannot know where whitespace is significant unless it is explicitly specified. – mzjn Jan 07 '21 at 13:30
0

Here is an easy way to add CSS styling to the HTML that Docbook outputs:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:m="http://docbook.org/ns/docbook/modes"
    version="2.0">

    <!-- Use Docbook from online content delivery network -->
    <xsl:import href="https://cdn.docbook.org/release/xsltng/current/xslt/docbook.xsl"/>
    <xsl:param name="docbook-xsltng-base" select="'https://cdn.docbook.org/release/xsltng/current'"/>
    <xsl:param name="resource-base-uri"   select="concat($docbook-xsltng-base, '/resources/')"/>

    <!-- Some CSS customizations -->
    <xsl:template match="*" mode="m:html-head-last">
        <style type="text/css">
            pre.literallayout {
                white-space: pre-wrap;
                background: #D0E0FF;
                padding: 1em;
                border-radius: 0.5em;
                line-height: normal;
                font-size: smaller;
                font-family: var(--mono-family);
            }
        </style>
    </xsl:template>

</xsl:transform>

The m:html-head-last mode is described here and is one of many points of customization.

Archie
  • 4,959
  • 1
  • 30
  • 36