Page numbers and its references in XSL-FO

To incert the current page number the <fo:page-number> is used. See a simple example below:

   <fo:static-content flow-name="xsl-region-after">
     <fo:block text-align="center">
       Page <fo:page-number/>
     </fo:block>
   </fo:static-content>

If you want to make a reference to a certain page use <fo:page-number-citation>. A referenced page must have a unique id. See the example below:

   ...
   <fo:block>
     ...Illegal drugs present a very big problem for the Government. 
     You can see the statistics on page <fo:page-number-citation ref-id="stat"/>. 
   </fo:block>
   ...
   <fo:table id="stat">
     ....
   </fo:table>

To get the total number of pages in the document there are two methods:

  1. You can use the <fo:page-number-citation-last> element.
       <fo:static-content flow-name="xsl-region-after">
         <fo:block text-align="center">
           Page <fo:page-number/> of <fo:page-number-citation-last/>
         </fo:block>
       </fo:static-content>
    
  2. And it is also possible to use already known <fo:page-number> element. In this case you should place an empty <fo:block> element at the end of the text and then make a reference to its page number.
       <fo:static-content flow-name="xsl-region-after">
         <fo:block text-align="center">
           Page <fo:page-number/> of <fo:page-number-citation ref-id="end"/>
         </fo:block>
       </fo:static-content>
       ...
       <fo:block id="end"/>