Question

I am having a problem with the way XSL-FO handles page numbering. In my application, I'm using Apache FOP to transform XML into PNG content. This PNG content is then "appended" to content from TIFF files to create the appearance of a single, continuous document. One of our requirements is to add page numbers to the PNG content. The catch, however, is that the page numbering needs to begin as if it was in sequence, i.e., if there are 2 pages of TIFF content, the first PNG page would be page 3.

Calculating the number of pages of TIFF content is easy and I pass it into the transformer as a parameter.

// setup XSLT
TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslFile));
transformer.setParameter("tiffPgOffset", getTiffPgOffset());

and I added the parameter to my XSL file to handle the page offset count.

   <xsl:param name="tiffPgOffset" />

I can access the parameter value inside the page just fine.

  <fo:static-content flow-name="xsl-region-after" font-family="Arial">
    <fo:block font-size="16">Page 
      tiffPgOffset = <xsl:value-of select="$tiffPgOffset" />   <!-- it works here -->
    </fo:block>
  </fo:static-content>

The problem occurs when I want to pass the parameter value to the page-sequence object. Given what I had read, I thought that this should work:

 <fo:page-sequence master-reference="main" initial-page-label="$tiffPgOffset">   <!-- this does not work -->

but it doesn't. Instead, I get the following run-time error:

Invalid property encountered on "fo:page-sequence": initial-page-label (No context info available)

I'm not sure what I'm doing wrong, but I'm hoping it will be painfully obvious to someone who has more experience with this. Thanks in advance.

Was it helpful?

Solution

Try using an AVT in the initial-page-number attribute:

initial-page-number="{$tiffPgOffset}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top