How to manipulate page number in FOP?

2019-05-13 06:15发布

问题:

I am using Apache FOP 0.95, and all I want to do is add 1 to the current page number.

So, on page 12, I want to show 12 / 13. Then nothing on page 13, of course.

Any ideas how I could do this, perhaps by manipulating <fo:page-number /> ?

Thanks y'all!

回答1:

Short answer for this is that you can't achieve the result you after with straight FO.

This is because you can't programatically access the page-numbers until FOP has assigned them, so your XSLT doesn't know what they are.

You can get round this using a 2 pass approach, where you manipulate the intermediate format (after its been through FOP) and re-process into target format. At least this is the approach I use when using RenderX XEP (Other XSL-FO Renderer) using its XEPOUT format (I assume FOPs works in a similar way see http://xmlgraphics.apache.org/fop/0.94/intermediate.html).

Cheers, Mike