Assuming an input XML document such as this one:
<AuthorList>
<Author>
<name>John Steinbeck</name>
<biography>John Ernst Steinbeck, Jr. (February 27, 1902 – December 20, 1968) was an American author of twenty-seven books, including sixteen novels, six non-fiction books
</biography>
<picture>
http://upload.wikimedia.org/wikipedia/commons/e/e7/John_Steinbeck_1962.jpg
</picture>
</Author>
<Author>
<name>William Faulkner</name>
<biography>William Cuthbert Faulkner (September 25, 1897 – July 6, 1962) was an American writer and Nobel Prize laureate from Oxford, Mississippi.
</biography>
<picture>
http://upload.wikimedia.org/wikipedia/commons/f/f3/William_Faulkner_1949.jpg
</picture>
</Author>
</AuthorList>
I want to create a PDF with the first page(s) showing a "kind of" table of content, e.g. just a table with author names and an internal link to their full page. The rest of the PDF should be detailed sheets about each author, containing bio, picture, etc. 1 page per author.
I have already written a piece of code like this:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" indent="yes" />
<xsl:template match="AuthorList">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<!-- Layout for the table of content -->
<fo:simple-page-master master-name="table" page-height="29.7cm" page-width="21cm" margin="1cm">
<fo:region-body column-count="1" background-color="transparent" />
<fo:region-after extent="2cm" />
</fo:simple-page-master>
<!-- Layout for individual sheets -->
<fo:simple-page-master master-name="sheet" page-height="21cm" page-width="29.7cm" margin="2cm">
<fo:region-body column-count="1" background-color="transparent" />
</fo:simple-page-master>
</fo:layout-master-set>
<!-- First part of the PDF output: table of content -->
<fo:page-sequence master-reference="table">
<fo:flow flow-name="xsl-region-body">
<fo:block>
Must put here the table of content
</fo:block>
</fo:flow>
</fo:page-sequence>
<!-- Second part of the PDF output: sheets for authors -->
<xsl:apply-templates select="Author"/>
</fo:root>
</xsl:template>
<xsl:template match="Author">
<fo:page-sequence master-reference="sheet">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="sans-serif" font-size="22pt" text-align="center">
<xsl:apply-templates select="name" />
</fo:block>
<fo:block font-family="sans-serif" font-size="12pt" text-align="justify">
<xsl:apply-templates select="biography" />
</fo:block>
</fo:flow>
</fo:page-sequence>
</xsl:template>
</xsl:stylesheet>
I'm now facing some problems:
- How can I create the table in the beginning of the PDF? I thought I could have an xsl:template matching author to add rows to the table, but since I already have one that is being used to produce the detailed sheets for the author, how can I differentiate the two of them?
- How can I introduce hyperlinks from elements in the table to the corresponding page for each author?
- I am also interested in suggestions for improvement, e.g. I put each author sheet in a page sequence, but probably I dont need that, although I do want each author page to be displayed in it's own page
I'm using apache-fop to produce the PDF.
Note that I have full hand at the way the original XML is produced so I could change the structure if that helps.