3

Consider the DocBook article in test.xml which contains an <informaltable> that is repeated at the beginning of each section. Consider also that the <informaltable> is actually much more complicated than this example shows.

This example accomplishes reuse of the complicated <informaltable> using an external <!ENTITY ... SYSTEM ...> declaration. The complicated <informaltable> is in another file called reusedtable.xml.

test.xml

<!DOCTYPE article [<!ENTITY ReusedTable SYSTEM "reusedtable.xml">]>

<article xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
<info>
    <title>Article Template Title</title>
</info>
<section>
    <title>first title</title>
    &ReusedTable;
</section>
<section>
    <title>Second Title</title>
    &ReusedTable;
</section>
</article>

reusedtable.xml

The file that contains the reused table.

<informaltable>
    <tgroup cols='2'>
        <tbody>
            <row>
                <entry>YES</entry>
                <entry>NO</entry>
            </row>
        </tbody>
    </tgroup>
</informaltable>

Here's what the output looks like

This method works, but it seems a bit awkward and limited. So it leaves me with the following questions:

  1. Is there a way to accomplish the reuse of my <informaltable> without creating a second .xml file?
  2. Is there a way to accomplish the reuse of my <informaltable> so that I could parameterize the table?

For example, I'd like to be able to express the presence of an instance of ReusedTable populated with different content in my docbook article like this,

test2.xml

<article xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
<info>
    <title>Article Template Title</title>
</info>
<section>
    <title>first title</title>
    <ReusedTable>
        <firstcol>true</firstcol>
        <seccol>false</seccol>
    </ReusedTable>    </section>
<section>
    <title>Second Title</title>
    <ReusedTable>
        <firstcol>yes</firstcol>
        <seccol>no</seccol>
    </ReusedTable>
</section>
</article>

and have the published output look like this where the design of ReusedTable is defined once and the content of the cells in each instance of ReusedTable comes from markup in the article where the table will appear.

alx9r
  • 3,675
  • 4
  • 26
  • 55
  • You say that you want to "call" the table, which sounds rather odd. What do you mean by that? – mzjn Jul 28 '12 at 17:52
  • 1
    How does using a system entity defy the spirit of XML? You could put your informaltable directly in the entity instead of having a second XML file, but then you couldn't use the table in any other files. I don't think that's much better. – Daniel Haley Jul 28 '12 at 18:38
  • @mjzn Admittedly "call" is not the best term. I've edited the question to hopefully make it a bit more clear. – alx9r Jul 29 '12 at 04:31
  • @DevNull I think my statement about the spirit of XML isn't well founded. What I was really griping about was over-modularizing my document into two separate files -- the ReusedTable would only ever be used in this one article anyway. – alx9r Jul 29 '12 at 04:52
  • @DevNull I tried your suggestion of putting the ReusedTable directly into the entity declaration and eventually got it to work. For some reason I was operating under the assumption that multiline entity declarations are not supported. Oxygen XML seems to support them just fine. So, putting the ReusedTable directly in the entity declaration seems to be the answer to my question #1. – alx9r Jul 29 '12 at 04:56
  • "*I'd like to be able to express the presence of an instance of ReusedTable populated with 'true' and 'false' in my docbook article...*". You can do that. Invent whatever specialized markup you like. But XML markup by itself just sits there; it does not do anything. What do you want to do with it? – mzjn Jul 29 '12 at 09:01
  • I added a picture of what I want the published output of 'test2.xml' to look like -- hopefully that makes my goal a bit more clear. Could you elaborate on "You can do that." The `ReusedTable` entity in 'test2.xml' is not part of the DocBook schema so produces validation errors. I assume that the schema could be extended to include this new entity (there are examples for how to do this), but how do I tell my tools to translate `ReusedTable` into the table I want when they encounter `ReusedTable`. I've searched unsuccessfully for an example of an xsl template that handles a schema extension. – alx9r Jul 29 '12 at 17:50
  • 1
    What I mean by "you can do that" is that you you are free to customize the schema in any way you want. If you decide to create a proper DocBook schema customization then you will get no validation errors if you do it right. However, I find it a bit hard to get to the core of the matter here. I am still struggling to understand exactly what you want to do and why you want to do it. Now you are asking about XSL stylesheets too, in addition to all the other issues you have brought up. I don't know where to start... :-). – mzjn Jul 29 '12 at 19:05
  • Question #1 is answered. I think question #2 should probably be separated out as I think question #1 is obfuscating the heart of the matter of question #2. I'll have to spend some time in meta to figure out how to properly do that. Regardless, I appreciate your help. – alx9r Jul 30 '12 at 04:58
  • 1
    You can provide an answer to #1 [yourself](http://meta.stackexchange.com/a/12519/155793) if you want to and create one or more new questions for the other issues. – mzjn Jul 30 '12 at 06:47

2 Answers2

1
  1. Is there a way to accomplish the reuse of my <informaltable> without creating a second .xml file?

Yes, also by declaring an entity but putting the <informaltable> inline by omitting the SYSTEM keyword in the declaration. This eliminates the need for another file altogether. Test.xml from the original question looks like this with the entity declarations inline:

Test.xml

<!DOCTYPE article [
<!ENTITY ReusedTable "
<informaltable>
    <tgroup cols='2'>
        <tbody>
            <row>
                <entry>YES</entry>
                <entry>NO</entry>
            </row>
        </tbody>
    </tgroup>
</informaltable>
">
]>

<article xmlns="http://docbook.org/ns/docbook"
    xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
    <info>
        <title>Article Template Title</title>
    </info>
    <section>
        <title>first title</title>
        &ReusedTable;
    </section>
    <section>
        <title>Second Title</title>
        &ReusedTable;
    </section>
</article>
Community
  • 1
  • 1
alx9r
  • 3,675
  • 4
  • 26
  • 55
1

Probably a better way to include complex tables (or other parts) is through XInclude see also this question and answer Can ENTITY declarations be nested in referenced XML files? As each tables content is different, there is no way to dynamically have that content updated, during the render process. If this indeed is what you need, then a way to solve the issue, is generate the (complex) tables, through a small program, as separate xml files. And include these separate xml files through XInclude in your document.

Community
  • 1
  • 1
Verhagen
  • 3,885
  • 26
  • 36