title: How to show page number (N of N) using xslt in PDF Report
body: <p>I am using XSLT to generate PDF report. My requirements are to display page number in the format of Page N of N (e.g.Page 1 of 3) at the footer of the report. For static values it works fine and it repeats on each page. As total number of pages in the report are not known and it changes run time, so how I will accomplish this task.</p>
  
  <p>My XSLT code snippet</p>
  
  <pre><code>&lt;xsl:template name="footerall"&gt;
  &lt;xsl:variable name="maxwidth" select="7.07000" /&gt;
  &lt;fo:static-content flow-name="xsl-region-after"&gt;
  &lt;fo:block&gt;
  &lt;xsl:variable name="tablewidth29" select="$maxwidth * 1.00000" /&gt;
  &lt;xsl:variable name="sumcolumnwidths29" select="0.04167 + 1.56250 + 0.04167" /&gt;
  &lt;xsl:variable name="factor29"&gt;
  &lt;xsl:choose&gt;
  &lt;xsl:when
  test="$sumcolumnwidths29 &amp;gt; 0.00000 and $sumcolumnwidths29 &amp;gt; $tablewidth29"&gt;
  &lt;xsl:value-of select="$tablewidth29 div $sumcolumnwidths29" /&gt;
  &lt;/xsl:when&gt;
  &lt;xsl:otherwise&gt;
  &lt;xsl:value-of select="1.000" /&gt;
  &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:variable name="defaultcolumns29" select="1" /&gt;
  &lt;xsl:variable name="defaultcolumnwidth29"&gt;
  &lt;xsl:choose&gt;
  &lt;xsl:when test="$factor29 &amp;lt; 1.000"&gt;
  &lt;xsl:value-of select="0.000" /&gt;
  &lt;/xsl:when&gt;
  &lt;xsl:when test="$defaultcolumns29 &amp;gt; 0"&gt;
  &lt;xsl:value-of
  select="($tablewidth29 - $sumcolumnwidths29) div $defaultcolumns29" /&gt;
  &lt;/xsl:when&gt;
  &lt;xsl:otherwise&gt;
  &lt;xsl:value-of select="0.000" /&gt;
  &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:variable name="columnwidth29_0" select="$defaultcolumnwidth29" /&gt;
  &lt;xsl:variable name="columnwidth29_1" select="1.56250 * $factor29" /&gt;
  &lt;fo:table width="{$tablewidth29}in" border-collapse="separate"
  border-separation="0.04167in" color="black" display-align="center"&gt;
  &lt;fo:table-column column-width="{$columnwidth29_0}in" /&gt;
  &lt;fo:table-column column-width="{$columnwidth29_1}in" /&gt;
  &lt;fo:table-body&gt;
  &lt;fo:table-row&gt;
  &lt;fo:table-cell number-columns-spanned="2"
  padding-top="0.00000in" padding-bottom="0.00000in" padding-left="0.00000in"
  padding-right="0.00000in"&gt;
  &lt;fo:block padding-top="1pt" padding-bottom="1pt"&gt;
  &lt;fo:block text-align="center" space-before.optimum="-8pt"&gt;
  &lt;fo:leader leader-length="100%" leader-pattern="rule"
  rule-thickness="1pt" color="black" /&gt;
  &lt;/fo:block&gt;
  &lt;/fo:block&gt;
  &lt;/fo:table-cell&gt;
  &lt;/fo:table-row&gt;
  &lt;fo:table-row&gt;
  &lt;fo:table-cell
  font-size="inherited-property-value(&amp;apos;font-size&amp;apos;) - 2pt"
  text-align="left" padding-top="0.00000in" padding-bottom="0.00000in"
  padding-left="0.00000in" padding-right="0.00000in"&gt;
  &lt;fo:block padding-top="1pt" padding-bottom="1pt"&gt;
  &lt;fo:inline font-family="Courier" font-size="10px"&gt;
  &lt;xsl:value-of select="$My XPath to varaible" /&gt;
  &lt;/fo:inline&gt;
  &lt;fo:inline font-family="Courier" font-size="10px"&gt;
  &lt;xsl:text&gt; - &lt;/xsl:text&gt;
  &lt;xsl:text&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&lt;/xsl:text&gt;
  &lt;xsl:text&gt;Page 1 of 1&lt;/xsl:text&gt;
  &lt;/fo:inline&gt;
  &lt;fo:inline font-family="Courier" font-size="10px"&gt;
  &lt;xsl:value-of select="$My XPath to varaible" /&gt;
  &lt;/fo:inline&gt;
  &lt;/fo:block&gt;
  &lt;/fo:table-cell&gt;
  &lt;fo:table-cell
  font-size="inherited-property-value(&amp;apos;font-size&amp;apos;) - 2pt"
  text-align="right" padding-top="0.00000in" padding-bottom="0.00000in"
  padding-left="0.00000in" padding-right="0.00000in"&gt;
  &lt;fo:block padding-top="1pt" padding-bottom="1pt" /&gt;
  &lt;/fo:table-cell&gt;
  &lt;/fo:table-row&gt;
  &lt;/fo:table-body&gt;
  &lt;/fo:table&gt;
  &lt;/fo:block&gt;
  &lt;/fo:static-content&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>I will replace the string (Page 1 of 1) by a variable but how to handle this.</p>
  
  <p>Please help me.</p>