How to show page number (N of N) using xslt in PDF Report

You should add an id attribute to your fo:page-sequence element, and then use a page-number-citation-last.

<fo:page-sequence id="my-sequence-id">
  ...
  <xsl:text>Page </xsl:text>
  <fo:page-number-citation />
  <xsl:text> of </xsl:text>
  <fo:page-number-citation-last page-citation-strategy="all" ref-id="my-sequence-id"/>
  ...
</fo:page-sequence>

See the specs: http://www.w3.org/TR/xslfo20/#fo_page-number-citation and http://www.w3.org/TR/xslfo20/#fo_page-number-citation-last


I solved my problem by following below instructions.

Put a formatting object with an id at the end of the area. You can then do a to the labeled block that appears on the last page of the document. Here's how the markup looks:

<fo:flow flow-name="xsl-region-body">
... Lots and lots of content here
<fo:block id="TheVeryLastPage"> </fo:block>
</fo:flow>

The code creates a block with an id of TheVeryLastPage (a value that's unlikely to be used by anyone), and now you can refer to that id to get the page number of the last page of the document. Here's how the content in the area should look:

<fo:block text-align="end">
Page <fo:page-number/> of 
<fo:page-number-citation 
ref-id="TheVeryLastPage"/>
</fo:block>

When FOP formats this markup, it generates something like "Page 2 of 5".

My reference URL is: http://www.ibm.com/developerworks/xml/tutorials/x-xslfo2/section4.html