Is there a better method than <!ENTITY> to reuse a complicated table in DocBook?

两盒软妹~` 提交于 2020-01-04 15:14:13

问题


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.


回答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.




回答2:


  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>


来源:https://stackoverflow.com/questions/11680142/is-there-a-better-method-than-entity-to-reuse-a-complicated-table-in-docbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!