有没有比 <!ENTITY> 更好的方法?在 DocBook 中重用复杂的表? [英] Is there a better method than <!ENTITY> to reuse a complicated table in DocBook?

查看:27
本文介绍了有没有比 <!ENTITY> 更好的方法?在 DocBook 中重用复杂的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑 test.xml 中的 DocBook 文章,其中包含在每个部分的开头重复的 .还要考虑 实际上比这个例子显示的要复杂得多.

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.

此示例使用外部 声明实现了对复杂 的重用.复杂的 位于另一个名为reusedtable.xml 的文件中.

This example accomplishes reuse of the complicated <informaltable> using an external <!ENTITY ... SYSTEM ...> declaration. The complicated <informaltable> is in another file called reusedtable.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

包含重用表的文件.

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>

输出如下

这个方法有效,但是看起来有点别扭和局限.所以它给我留下了以下问题:

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

  1. 有没有办法在不创建第二个 .xml 文件的情况下实现我的 的重用?
  2. 有没有办法实现我的 的重用,以便我可以参数化表格?
  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?

例如,我希望能够像这样在我的 docbook 文章中表达一个填充有不同内容的 ReusedTable 实例的存在,

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,

<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>

并发布输出看起来像这样,其中 ReusedTable 的设计定义一次并且 ReusedTable 的每个实例中单元格的内容来自文章中将出现表格的标记.

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.

推荐答案

包含复杂表(或其他部分)的更好方法可能是通过 XInclude 另见此问题和答案 实体声明可以嵌套在引用的 XML 文件中吗?由于每个表的内容不同,因此无法在渲染过程中动态更新该内容.如果这确实是您所需要的,那么解决问题的一种方法是通过一个小程序将(复杂)表生成为单独的 xml 文件.并通过 XInclude 在您的文档中包含这些单独的 xml 文件.

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.

这篇关于有没有比 &lt;!ENTITY&gt; 更好的方法?在 DocBook 中重用复杂的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆