XSL-FO creating Dynamic Table Of Contents

两盒软妹~` 提交于 2019-12-20 04:22:25

问题


How we can create a table of contents page dynamically in XSL-FO?


回答1:


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.



来源:https://stackoverflow.com/questions/7159747/xsl-fo-creating-dynamic-table-of-contents

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