XSL-FO Tutorials - Herong's Tutorial Examples - v2.24, by Herong Yang
Building Back-of-Book Indexes
This section provides a tutorial example on how to build a clickable back-of-book indexes with hyperlinks using index-key attributes and index-page-citation-list formatting objects.
XSL-FO also supports another type of hyperlink called indexing links. When you build back of the book indexes, you can make their page numbers as hyperlinks. Here are some basic steps to build indexes with hyperlinks:
1. Create a unique index key for each term you want to be indexed.
2. Associate the index key to formatting objects that relevant to the term using the index-key="..." attribute.
3. Insert the term on the index list and generate a list of cited page numbers referring to locations of those relevant formatting objects. This can be done with the "index-page-citation-list" formatting object as shown below:
Some Term <fo:index-page-citation-list merge-sequential-page-numbers="leave-separate"> <fo:index-key-reference ref-index-key="..." page-number-treatment="link"/> </fo:index-page-citation-list>
Note that attribute index-key-reference[@page-number-treatment="link"] is to make cited page numbers as hyperlinks.
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"?> <!-- index-page-citation-list-and-index-key.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="2.2in" page-width="1.7in"> <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" index-key="Pooh"> Winnie the Pooh </fo:block> <fo:block margin="0.08in" font-size="8pt" font-weight="bold" id="chapter-1" text-align="center"> Chapter One </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> Here is <fo:inline index-key="Bear">Edward Bear</fo:inline>, coming downstairs now, bump, bump, bump, on the back of his head, behind <fo:inline index-key="Robin">Christopher Robin</fo:inline>. 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. <fo:inline index-key="Pooh">Winnie-the-Pooh</fo:inline>... </fo:block> <fo:block margin="0.08in" font-size="8pt" font-weight="bold" id="chapter-2" break-before="page" text-align="center"> Chapter Two </fo:block> <fo:block margin="0.08in" font-size="8pt" text-align="justify"> <fo:inline index-key="Bear">Edward Bear</fo:inline>, 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="8pt" font-weight="bold" id="reference" break-before="page" text-align="center"> Index </fo:block> <fo:block margin-left="6pt" font-size="8pt"> Christopher Robin <fo:inline color="#0000ff"> <fo:index-page-citation-list merge-sequential-page-numbers="leave-separate"> <fo:index-key-reference ref-index-key="Robin" page-number-treatment="link"/> </fo:index-page-citation-list> </fo:inline> </fo:block> <fo:block margin-left="6pt" font-size="8pt"> Edward Bear <fo:inline color="#0000ff"> <fo:index-page-citation-list merge-sequential-page-numbers="leave-separate"> <fo:index-key-reference ref-index-key="Bear" page-number-treatment="link"/> </fo:index-page-citation-list> </fo:inline> </fo:block> <fo:block margin-left="6pt" font-size="8pt"> Winnie the Pooh <fo:inline color="#0000ff"> <fo:index-page-citation-list merge-sequential-page-numbers="leave-separate"> <fo:index-key-reference ref-index-key="Pooh" page-number-treatment="link"/> </fo:index-page-citation-list> </fo:inline> </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
Since Apache FOP does not support index-key="...", you need to use RenderX XEP to process this example. Indexes are listed on page 5 as shown below:
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
►Building Back-of-Book Indexes
Headers and Footers using "static-content"
Font Attributes and Font Families
Apache FOP Font Configurations