xsl-fo page numbering

Here should go questions about transforming XML with XSLT and FOP.
sharma_kv
Posts: 6
Joined: Mon Nov 01, 2004 6:08 am

xsl-fo page numbering

Post by sharma_kv »

Thank you George for helping me solve the problem. In fact, it was a data issue and thus the distortion.
I am experiencing one more problem.
If the page to be displayed is 1, still in the PDF displays as 1 of 2 and the second page blank. But if there is more than 1 page, it displays to perfection. Can you please give me suggestions so that i can incorportate.
Thanks a lot
sharma_kv
Posts: 6
Joined: Mon Nov 01, 2004 6:08 am

xsl-fo page numbering

Post by sharma_kv »

I have found out a part of a solution for the problem I posed. This was happening becoz I have two <fo:flow> and the citation <fo:block id="terminator"/> was declared at the end of the <fo:flow> block. But I should have two flows as it has some business logic and based on that it goes to respective flows. Does that mean I cant have two ids in two diff flows??wht is the solution for it. How can I make it generic. (P.S. Still the blank page is being displayed if the page is 1)> Please help me
Thanks a lot
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Sample, please

Post by Radu »

Hi,

We are having trouble creating a document to duplicate your problem.

Could you send a sample of the fo document for which you are experimenting this problem ( this means removing all sensitive data and leaving only the structure of the document).

Regards, Radu.
sharma_kv
Posts: 6
Joined: Mon Nov 01, 2004 6:08 am

xsl-fo page numbering

Post by sharma_kv »

Thanks for the instant reply
Please find my xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xalan="http://xml.apache.org/xalan" xmlns:java="http://xml.apache.org/xslt/java">
<xsl:output method="xml" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<fo:root>
<!-- ================================================================ -->
<!-- Page Setup. -->
<!-- ================================================================ -->
<fo:layout-master-set>
<fo:simple-page-master master-name="main" page-width="210mm" page-height="297mm" margin-top="10mm" margin-bottom="10mm" margin-right="3mm" margin-left="1cm">
<fo:region-body margin-top="7mm"/>
<fo:region-before extent="5mm"/>
<fo:region-after extent="5in" region-name="footer"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="second" page-width="210mm" page-height="297mm" margin-top="10mm" margin-bottom="10mm" margin-right="3mm" margin-left="1cm">
<fo:region-body margin-top="7mm"/>
<fo:region-before extent="5mm"/>
<fo:region-start margin-top="5mm" extent="7.5in" region-name="header-second"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="rest" page-width="210mm" page-height="297mm" margin-top="10mm" margin-bottom="10mm" margin-right="3mm" margin-left="1cm">
<fo:region-body margin-top="7mm"/>
<fo:region-before extent="5mm"/>
<fo:region-start margin-top="5mm" extent="7.5in" region-name="header-rest"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="mainpage">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="main"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
<fo:page-sequence-master master-name="secondandrest">
<fo:single-page-master-reference master-reference="second"/>
<fo:repeatable-page-master-reference master-reference="rest"/>
</fo:page-sequence-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="mainpage">
<fo:static-content flow-name="footer">
<!-- Some data -->


</fo:static-content>

<fo:flow flow-name="xsl-region-body">
<!-- ================================================================ -->
<!-- CHECK FIRST PAGE CONTENT -->
<!-- ================================================================ -->
<xsl:if test="count(EOP/CHCK) >0">
<fo:block end-indent="10pt" text-align="end" white-space-collapse="false" font-family="Courier New, Courier" font-size="9pt" font-weight="bold">
<fo:page-number/> of <fo:page-number-citation ref-id="terminator"/></fo:block>
<!-- some business logic -->
</xsl:if>
</fo:flow>
</fo:page-sequence>

<fo:page-sequence master-reference="secondandrest">

<fo:static-content flow-name="header-second">

<!-- ================================================================ -->
<!-- CHECK HEADER SECOND PAGE CONTENT -->
<!-- ================================================================ -->
<xsl:if test="count(EOP/CHCK/DETL) >0">
<fo:block text-align="end" white-space-collapse="false" font-family="Courier New, Courier" font-size="9pt" font-weight="bold">
<fo:page-number/> of <fo:page-number-citation ref-id="terminator"/></fo:block>

</xsl:if>
</fo:static-content>

<fo:static-content text-align="left" flow-name="header-rest">

<!-- header rest of the pages -->
</fo:static-content>


<fo:flow flow-name="xsl-region-body">
<!-- ================================================================ -->
<!-- for other groups -->
<!-- ================================================================ -->
<xsl:if test="count(EOP/EFT) >0">
<!-- I have to have this id as sometimes it goes to the other loop and based on some other business logic, comes to this loop
<fo:block id="terminator"/>
</xsl:if>
<!-- ================================================================ -->
<!-- for other business CONTENT -->
<!-- ================================================================ -->
<xsl:if test="count(EOP/CHCK) >0">
<!-- business logic again -->
<fo:block id="terminator"/>
</xsl:if>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>



The problem is if the page content is more than 2 pages, it display to pefection. But if the page is 1, it displays as 1 of 2 and the second page blank. IN fact , it should be 1 of 1 and no second page at all. Hope i made sense. Thanks a lot for helping me
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Analysis

Post by Radu »

I started by transforming the xsl file you provided against an xml file ("samples/personal.xml" in my case).
I unchecked the "Perform FO Processing" option and saved the result as "test.fo". To this output file I associated the "frameworks/fo/xsd/fo.xsd" schema and attempted a validation.
The first error is that the "fo:region-start" tag does not allow the "margin-top" attribute.
The other errors refer to this piece of the output:

Code: Select all

     <fo:page-sequence master-reference="secondandrest">
<fo:static-content flow-name="header-second"/>
<fo:static-content text-align="left" flow-name="header-rest"/>
<fo:flow flow-name="xsl-region-body"/>
</fo:page-sequence>

Of course, these last errors appeared because I used a wrong XML file.

Basically "fo:static" and "fo:flow" tags are required to have a fo:body content. I noticed that you use "xsl:if" statements to filter "fo:blocks" when the content to display is empty. These "xsl:if" statements should be best used to filter the whole "fo:page-sequence" block because an empty "fo:flow" like:

Code: Select all

         <fo:flow flow-name="xsl-region-body">
<fo:block></fo:block>
</fo:flow>
will produce a blank page.

So it would be best if you apply the XSL file against your XML data file and then try to check and validate the fo file that is the output from the transformation.
I also recommend this tutorial "http://www.renderx.net/Content/support/ ... orial.html" from RenderX.

Please tell us if you have any more problems in this area.
sharma_kv
Posts: 6
Joined: Mon Nov 01, 2004 6:08 am

xsl-fo

Post by sharma_kv »

Thanks a lotttt
I put an if codintion in the <fo:page-sequence master-reference="secondandrest"> and it worked!!!!.. Thanks a lot
Regards
KV
Post Reply