Thursday, 29 August 2013

How to preprocess xsl:fo document before pdf generation?

How to preprocess xsl:fo document before pdf generation?

consider the following xml:
<book>
<chapter>
<title>chapter title 1</title>
<id>chapterId1</id>
<content>some content</content>
</chapter>
<chapter>
<title>chapter title 2</title>
<id>chapterId2</id>
<content>some content</content>
</chapter>
</book>
I want to generate a book with table of contents. So i create the TOC like
so:
<xsl:for-each select="book/chapter">
<fo:block>
<xsl:value-of select="title" />
<fo:page-number-citation ref-id="id" >
<xsl:attribute name="ref-id">
<xsl:value-of select="id" />
</xsl:attribute>
</fo:page-number>
</fo:block>
</xsl:for-each>
the ref-id attribute is overwritten on the fly and replaced by the value
of the chapter id.
The problem here is that the referenced id are not yet knwon in the
document. Because I use the same <xsl:attribute> element to create set the
chapter id's on the cahpeter blocks.
<fo:block> <!-- the chapter container -->
<xsl:attribute name="id">
<xsl:value-of select="chapter/id" />
</xsl:attribute>
<fo:block>
the chapter content.....
</fo:block>
</fo:block>
How do I preprocess my xsl:fo file so that the fo:block elements have the
correct ID's already set?
Thank you

No comments:

Post a Comment