Henrik,
Your .fo file is an XML document. So, you need to write an XSL that can rewrite the .fo document with some minor changes. Lets say you follow my suggestion and your first XSL generates an .fo with <fo:inline placeholder="PutTotalPagesHere">1234</fo:inline> in those spots where you want the page total. (. . . hmmmmm that is a tough problem isn't it?)
OK. You have to then render the document using FOP because FOP is the only thing that's going to know how many pages are rendered. You'll have to capture the total number of pages from FOP using that Java variable which I saw referred to in a post about 3 weeks ago (anyone?) and then rewrite the .fo using an XSL like this. Passing in the value for the number of pages as a parameter to your stylesheet. I use saxon and the command line is something like
saxon -o output.fo input.fo rewrite.xsl TotalPages=24
There's a Java interface on most XSL processors that allow you to do the same thing. (Or, you could dynamically generate this XSL with the number of pages embedded)
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<xsl:output method="xml" version="4.0" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="TotalPages"/>
<xsl:template match="/"> <xsl:apply-templates mode="output"/> </xsl:template>
<xsl:template match="*" mode="output">
<!-- This template outputs the XML document as text -->
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:if test="count(./*) > 0">
<xsl:for-each select=".">
<xsl:apply-templates mode="output"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="string-length(.) > 0">
<xsl:if test="count(./*) = 0">
<xsl:value-of select="."/>
</xsl:if>
</xsl:if>
</xsl:element>
</xsl:template><xsl:template match="fo:[EMAIL PROTECTED]" mode="output"> <xsl:value-of select="$TotalPages"/> </xsl:template>
</xsl:stylesheet>
Chuck Paussa
Henrik Holle wrote:
can you please explain me how to count the page in a fo with an xslt?
>-----Ursprungliche Nachricht-----
>Von: Chuck Paussa [mailto:[EMAIL PROTECTED]
>Henrik,
>
>There is no way to do what you want in FO in one pass. What you'll need to do is generate the fo: document with some marked up place holders in it. Something like <fo:inline placeholder="PutTotalPagesHere"/>. Then run that document through an XSLT transformation that adds up the total number of pages and replaces those special blocks with the information you want. (You'll see this technique referred to in the archives as "Making a second pass" over the document.) You can then use FOP to generate the output you want.
>
>Chuck
>
> > Henrik Holle wrote:
> >
> > I have various page-sequences in my document:
> >
> > <fo:page-sequence master-reference="NameOfMasterReference" initial-page-number="1">
> >
> > but at the end of the document i need to count the whole pages of all page-sequences.
> >
> > !<fo:page-number-citation ref-id = "lastBlock"/>! does not work!
> > -----Ursprungliche Nachricht-----
> > Von: Ian Taylor [mailto:[EMAIL PROTECTED]
> >
> > I put this in my <xsl:region-after>
> >
> > <fo:block font-size="9pt" line-height="11pt" text-align="end"> Page no: <fo:page-number/> of <fo:page-number-citation ref-id = "lastBlock"/> </fo:block> where the last block in the document looks like this <fo:block id = "lastBlock"/>
> >
> > Ian
> > At 12:54 PM 4/24/2002 +0200, you wrote:
> >
> > Hello,
> >
> > I want to write something like "page x of y" where y is the number of pages in my document. "x" is generated by "<fo:page-number/>" but how do I get "y"??
> >
> > Harald
