Re: [xsl] Total number of pages with XSL-FO

Subject: Re: [xsl] Total number of pages with XSL-FO
From: JBryant@xxxxxxxxx
Date: Thu, 14 Apr 2005 13:44:01 -0500
Hi, Nadia,

You are generating the .fo document from an XML source via an XSL 
stylesheet, right? So how can the last-page block be in the fo already? I 
must not have a proper grasp of your process.

Anyway, to make page x of y work correctly, you need to put in an empty 
block with the ID, as your predecessor mentioned. If you put the ID on an 
actual content block, you run the risk of the content within the block 
crossing a page boundary and making your page total be off by one (or more 
if you have a really big block). Fortunately, you can make the empty block 
be very small, so that it is unlikely to trigger a new page. Try this:

<fo:block id="last-page" line-height="0"/>

If you want to be absolutely sure that content appears on the last page, 
put the last block that has content and the empty block into a table that 
has two rows (one for each block). Then set keep-with-next="always" on the 
first row. That way, the empty block can never be on a page by itself.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

04/14/2005 12:12 PM
Please respond to


Re: [xsl] Total number of pages with XSL-FO

Well I tried and it does not work.  I suspect that it is because the id
'last-page' is in the actual .fo document, no in the xml.

here is a code snippet:

      <xsl:when test="//fo:block/@id='last-page'">
            Page <fo:page-number/> of <fo:page-number-citation
            Page 1 of 1

<!--snip to block with id='last-page'-->

<fo:static-content flow-name="xsl-region-after-otherlast">
      <fo:block id="last-page" space-before="12pt"
            <fo:leader leader-pattern="rule" leader-length="100%"
rule-thickness="0.5pt" rule-style="solid" color="black"/>

Somehow, I think there is no way to get that xsl:choose to work.

I talked to the guy that worked on this before me.  The original 
had an empty block at the end of the document and that block had the id 
to "last-page".  The problem was that it cause a new empty page to be
displayed in some cases, and it was taken out.

My guess is that I am going to have to take it out and hope that the
custodians and users do not mind just having a page number, instead of the
total number of pages.

Nadia Swaby

                      m                        To: 
                      2005-04-14 11:43         Subject: Re: [xsl] Total 
number of pages with XSL-FO 
                      Please respond   
                      to xsl-list   

> So here is my next question: is there any way to see if an id
> exists in an FO document?
> Nadia Swaby

Hi, Nadia,

Sure. You can do a test for it in either xsl:when or xsl:if. For example:

<xsl:if test="//@id='MyID'">
  <!-- Do something (perhaps apply certain templates) -->

Of course, if you can determine the exact path (not always possible
because elements may be nested at different depths and so on), you can use
the actual path instead of //.


Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

Current Thread