开发者

XSL-FO creating Dynamic Table Of Contents

How we开发者_开发百科 can create a table of contents page dynamically in XSL-FO?


What I've done in the past is use <fo:page-number-citation> for each entry in the TOC (Table of Contents). I do the table of contents as an <fo:table>.

The <fo:page-number-citation> has a ref-id attribute that should contain the id of the location you're referencing. It should generate the PDF page number where that id is located.

For example, if you wanted each <chapter> referenced in your TOC, you would use <fo:page-number-citation> with a ref-id that matched the id of where the <chapter> was output (like fo:page-sequence, fo:block, etc.).

Here's an example. I'm basing the id attribute on the value of an existing attribute, but you can generate an id if you need to.

Example Chapter XML:

<chapter foo="CHAP-1">
...
</chapter>

Example entry in the TOC table:

<fo:table-cell>
  <fo:block>
    <fo:page-number-citation ref-id="CHAP-1"/>
  </fo:block>
</fo:table-cell>

Example of outputting the <chapter>:

<fo:page-sequence id="CHAP-1">
...
</fo:page-sequence>

You can also wrap the fo:page-number-citation in an fo:basic-link to link the page number in the TOC to the actual page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜