XSL-FO Tutorials - Herong's Tutorial Examples - v2.24, by Herong Yang
Clickable Table of Content
This section provides a tutorial example on how to build a clickable table of content with hyperlinks using 'basic-link' formatting objects with 'internal-destination' attributes.
One good use of hyperlinks with "internal-destination" attributes it build a table of content with each entry as a hyperlink. So the user can click on a chapter or a section in the table of content to jump to the page where the chapter or section is located.
Here is my tutorial example, basic-link-table-of-content.fo, that uses "internal-destination" hyperlinks to build a table of content:
<?xml version="1.0" encoding="utf-8"?> <!-- basic-link-table-of-content.fo - Copyright (c) 2006 HerongYang.com. All Rights Reserved. --> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="page" margin="0.08in" page-height="3.3in" page-width="2.55in"> <fo:region-body region-name="body" background-color="#eeeeee"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="page"> <fo:flow flow-name="body"> <fo:block margin="0.08in" font-size="10pt" font-weight="bold"> Winnie the Pooh </fo:block> <fo:block margin="0.08in" font-size="6pt" font-weight="bold" text-align="center"> Table of Content </fo:block> <fo:block margin="0.08in" font-size="6pt" text-align-last="justify" color="#0000ff"> <fo:basic-link internal-destination="chapter-1"> Chapter One <fo:leader leader-pattern="dots"/> <fo:page-number-citation ref-id="chapter-1"/> </fo:basic-link> </fo:block> <fo:block margin="0.08in" font-size="6pt" text-align-last="justify" color="#0000ff"> <fo:basic-link internal-destination="chapter-2"> Chapter Two <fo:leader leader-pattern="dots"/> <fo:page-number-citation ref-id="chapter-2"/> </fo:basic-link> </fo:block> <fo:block margin="0.08in" font-size="6pt" text-align-last="justify" color="#0000ff"> <fo:basic-link internal-destination="reference"> Reference <fo:leader leader-pattern="dots"/> <fo:page-number-citation ref-id="reference"/> </fo:basic-link> </fo:block> <fo:block margin="0.08in" font-size="6pt" font-weight="bold" id="chapter-1" text-align="center"> Chapter One </fo:block> <fo:block margin="0.08in" font-size="6pt" text-align="justify"> Here is Edward Bear, coming downstairs now, bump, bump, bump, on the back of his head, behind Christopher Robin. It is, as far as he knows, the only way of coming downstairs, but sometimes he feels that there really is another way, if only he could stop bumping for a moment and think of it. And then he feels that perhaps there isn’t. Anyhow, here he is at the bottom, and ready to be introduced to you. Winnie-the-Pooh... </fo:block> <fo:block margin="0.08in" font-size="6pt" font-weight="bold" id="chapter-2" break-before="page" text-align="center"> Chapter Two </fo:block> <fo:block margin="0.08in" font-size="6pt" text-align="justify"> Edward Bear, known to his friends as Winnie-the-Pooh, or Pooh for short, was walking through the forest one day, humming proudly to himself. He had made up a little hum that very morning, as he was doing his Stoutness Exercises in front of the glass: Tra-la-la, tra-la-la, as he stretched up as high as he could go, and then Tra-la-la, tra-la--oh, help!--la, as he tried to reach his toes. After breakfast he had said it over and over to himself until he had learnt it off by heart, and now he was humming it right through, properly. </fo:block> <fo:block margin="0.08in" font-size="6pt" font-weight="bold" id="reference" break-before="page" text-align="center"> References </fo:block> <fo:block id="A_A_Milne" margin="0.08in" font-size="6pt" text-align="justify"> A. A. Milne - Alan Alexander "A. A." Milne (January 18, 1882 – January 31, 1956) was an English author, best known for his books about the teddy bear Winnie-the-Pooh and for various poems. </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
If you process this example XSL-FO document with Apache FOP to a PDF file and open it with Adobe Acrobat Reader, you will see a clickable table of content on the fist page:
Table of Contents
Apache™ FOP (Formatting Objects Processor)
XSL-FO Document Basics and Examples
Block-Level Formatting Objects
Inline-Level Formatting Objects
Including Graphics in XSL-FO document
Floating Blocks - "float" and "footnote"
►Hyperlinks, Table of Contents and Indexes
What Is "basic-link" Formatting Object?
"basic-link" with "internal-destination" Attribute
Headers and Footers using "static-content"
Font Attributes and Font Families
Apache FOP Font Configurations