Search code examples
relative-pathdocbookxinclude

Insert a source file in programlisting with xinclude in docbook


I've the following file tree

mainfolder
|-assembly.xml
|
|-chapters
| |-introduction.xml
|
|-source
  |-example01
    |-main.cpp

assembly.xml is the assembly file of my docbook. It contains a reference to introduction.xml.

This is the assembly:

<?xml version="1.0" encoding="UTF-8"?>
<assembly version="5.1"
  xmlns="http://docbook.org/ns/docbook">
  <resources xml:base="chapters/">
    <resource href="introduction.xml" xml:id="introduction" />
  </resources>
  <structure xml:id="main-book">
    <info>
      <description>Book chapters</description>
    </info>
    <output renderas="book"/>
    <module resourceref="introduction"/>
  </structure>
</assembly>

introduction.xml is docbook chapter. I want to insert in it an example including the main.cpp.

<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.1"
  xmlns="http://docbook.org/ns/docbook"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:trans="http://docbook.org/ns/transclusion"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns:m="http://www.w3.org/1998/Math/MathML"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:db="http://docbook.org/ns/docbook">
  <info>
    <title>Introduction</title>
  </info>
  <section>
    <info>
      <title>Chapter title</title>
    </info>
    <para>
    You can see an example:
    </para>
    <example>
    <title>main example</title>
      <programlisting language="c++">
        <xi:include href="./../source/example01/maiin.cpp" parse="text" />
      </programlisting>
    </example>
  </section>
</chapter>

Anyway, when I build the book (I'm using personal edition of XMLMind), I don't see anything. In the PDF the example is printed, but instead of the source code inside the main.cpp I see

<xi:include></xi:include>

What I'm doing wrong? How can I include the source code from the file?


Solution

  • I've reproduced your situation in a different ways and got things working in a both cases.

    You didn't mention the exact steps you make to build a book using XMLMind XML Editor (XXE for short), but the following steps certainly worked well.

    None 1: I've used XXE Professional Edition, but as I know the difference between versions is only in putting random character within text if generating PDF from Personal Edition.

    Note 2: XXE says that <description>Book chapters</description> element is not allowed within you context. Despite that fact, the assembly can be generated successfully.

    1. Getting things working within XXE

    1. Open an assembly file in XXE.
    2. Select Convert > Convert document > Convert to PDF.
    3. Select a path to save pdf file and press OK button.

    2. Getting things working manually in command line

    1. Use your exact files and DIR structure (I included my own .c file sample for my own test).

    2. Use XXE assembly processor: http://www.xmlmind.com/xmleditor/assembly.shtml - it has the same codebase that XXE used for working with assemblies from XXE GUI.

    3. Get docbook book file from assembly:assembly-1_0_2_01/bin/assembly -v assembly.xml docbook_book.xml In my test I've got the .c sample file included - that proves that assembly utility works well with XInclude.

    4. Get .pdf manually: fop -c <config_file> -xsl <path_to_docbook_ns_stylesheets>/fo/docbook.xsl -xml docbook_book.xml -pdf docbook_book.pdf

    I've got the final result with .c sample included in both cases.