You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Andries Burger <an...@switchonline.co.za> on 2007/11/26 12:32:54 UTC

Problem generating PDF with FOP 0.94

Hi All,

I'm a newbie when it comes to using XSL and FOP to generate PDF's. I
inherited a print output program from another programmer and there has
been no documentation on how the printing or layouts are configured.
I've had to learn XSL/XSLT and the FOP and thus far I've managed to get
a .fo file generated for the layout I want, except that I end up with a
double <fo:root> element in the FO file.

My partial XSL looks like this:

<?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">

<xsl:decimal-format name="invoice" decimal-separator="."
grouping-separator="," infinity="" minus-sign="-" NaN="" percent="%"
per-mille="m" zero-digit="0" digit="#" pattern-separator=";"/>

<xsl:key name="htt" match="hospital_item" use="@tariff_type"/>

<xsl:template match="printspecification">

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

        <fo:layout-master-set>
            <fo:simple-page-master master-name="main" margin="1cm"
page-width="29.7cm" page-height="21cm">
                <fo:region-body margin="1cm 0cm 1cm 0cm"/>
                <fo:region-before extent="1cm"/>
                <fo:region-after extent="1cm"/>
            </fo:simple-page-master>
        </fo:layout-master-set>

        <xsl:apply-templates select="batch" />
        <xsl:apply-templates />

    </fo:root>

</xsl:template>

<xsl:template match="batch">
    <xsl:apply-templates select="scheme"/>
</xsl:template>

<xsl:template match="text()"/>

<xsl:template match="scheme">

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

        <fo:static-content flow-name="xsl-region-before">
            <fo:block font-size="10pt" border-width="0cm 0cm 0cm 0cm">
                <fo:table table-layout="fixed">
                    <fo:table-column column-width="3.5cm"/>
                    <fo:table-column column-width="5.5cm"/>
                    <fo:table-column column-width="10.7cm"/>
                    <fo:table-column column-width="8cm"/>
                    <fo:table-body>
                        <fo:table-row>

                            <fo:table-cell>
                                <fo:block text-align="center">
                                    BATCH NO : <xsl:value-of
select="../batch_no"/>
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell text-align="center">
                                <fo:block>
                                    BATCH DATE : <xsl:value-of
select="../batch_date"/>
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell>
                                <fo:block text-align="center">
                                    MEDICAL AID SCHEME : <xsl:value-of
select="scheme_name"/>
                                </fo:block>
                            </fo:table-cell>

                            <fo:table-cell>
                                <fo:block text-align="center">
                                    ADMINISTRATOR : <xsl:value-of
select="../administrator_name"/>
                                </fo:block>
                            </fo:table-cell>

                        </fo:table-row>
                    </fo:table-body>
                </fo:table>
            </fo:block>
        </fo:static-content>

        <fo:static-content flow-name="xsl-region-after">
            <fo:block border-color="black" border-width="0cm 0cm 0cm
0cm" border-style="solid" background-color="#d6540e" text-align="center"
padding="0cm 0cm 0cm 0cm">
                <fo:block font-size="10pt" padding="0cm 0cm 0cm
0cm">Queries can be tendered toll free 0800 111 703
(page<fo:page-number/>)</fo:block>
            </fo:block>
        </fo:static-content>

        <fo:flow flow-name="xsl-region-body">
            <xsl:apply-templates select="invoice"/>
        </fo:flow>

    </fo:page-sequence>

</xsl:template>
.
.
. -- Several other templates follow here before the file is closed off.

</xsl:stylesheet>

It's processed with xsltproc into the fo file.

I have been experiencing difficulty with the call to the "batch"
template in the <fo:root> section of the "printspecification" template.
If I leave off the <xsl:apply-templates /> tag, then I only get the
<fo:root><fo:layout-master> tag set in the output .fo file, like so:

<?xml version="1.0"?>
<fo:root
xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout-master-set><fo:s
imple-page-master master-name="main" margin="1cm" page-width="29.7cm"
page-height="21cm"><fo:region-body margin="1cm 0cm 1cm 0cm"
/><fo:region-before extent="1cm"/><fo:region-after
extent="1cm"/></fo:simple-page-master></fo:layout-master-set></fo:root>

but with the apply-templates tag, I get the rest of the template content
(and extracted data) from the XML file. Except, I end up with two
<fo:root> elements...

Here is the top part of the .fo file:

<?xml version="1.0"?>
<fo:root
xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout-master-set><fo:s
imple-page-master master-name="main" margin="1cm" page-width="29.7cm"
page-height="21cm"><fo:region-body margin="1cm 0cm 1cm 0cm"
/><fo:region-before extent="1cm"/><fo:region-after
extent="1cm"/></fo:simple-page-master></fo:layout-master-set><fo:root><f
o:layout-master-set><fo:simple-page-master master-name="main"
margin="1cm" page-width="
29.7cm" page-height="21cm"><fo:region-body margin="1cm 0cm 1cm
0cm"/><fo:region-before extent="1cm"/><fo:region-after
extent="1cm"/></fo:simple-page-master></fo:layout-master-set><fo:page-se
quence master-refere
nce="main"><fo:static-content flow-name="xsl-region-before"><fo:block
font-size="10pt" border-width="0cm 0cm 0cm 0cm"><fo:table
table-layout="fixed"><fo:table-column
column-width="3.5cm"/><fo:table-column colum
n-width="5.5cm"/><fo:table-column
column-width="10.7cm"/><fo:table-column
column-width="8cm"/><fo:table-body><fo:table-row><fo:table-cell><fo:bloc
k text-align="center">
                                    BATCH NO :
12345</fo:block></fo:table-cell><fo:table-cell
text-align="center"><fo:block>
                                    BATCH DATE :
20060728</fo:block></fo:table-cell><fo:table-cell><fo:block
text-align="center">
                                    MEDICAL AID SCHEME : 
      MATLABAS
      </fo:block></fo:table-cell><fo:table-cell><fo:block
text-align="center">
                                    ADMINISTRATOR :
WALTONS</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:ta
ble></fo:block></fo:static-content><fo:static-content
flow-name="xsl-region-after"><fo
:block border-color="black" border-width="0cm 0cm 0cm 0cm"
border-style="solid" background-color="#d6540e" text-align="center"
padding="0cm 0cm 0cm 0cm"><fo:block font-size="10pt" padding="0cm 0cm
0cm 0cm">Quer
ies can be tendered toll free 0800 111 703
(page<fo:page-number/>)</fo:block></fo:block></fo:static-content><fo:flo
w flow-name="xsl-region-body"><fo:table font-size="8pt"
table-layout="fixed"><fo:table-column c
olumn-width="5cm"/><fo:table-column column-width="5cm"/><fo:table-column
column-width="10cm"/><fo:table-column
column-width="3.5cm"/><fo:table-column
column-width="4.2cm"/><fo:table-body><fo:table-row height="0
.5cm"><fo:table-cell border-style="solid" border-width="0.01cm .01cm
.01cm .01cm" border-color="white"><fo:block text-align="center">
                        PRACTICE NO:
7654321</fo:block></fo:table-cell><fo:table-cell border-style="solid"
border-width="0.01cm .01cm .01cm .01cm" border-color="white"><fo:block
text-align="center">
                        NAME: VAN DER PLOES EN
KIE.</fo:block></fo:table-cell><fo:table-cell border-style="solid"
border-width="0.01cm .01cm .01cm .01cm" border-color="white"><fo:block
text-align="center">DONKI
EDROL STRAAT 5, PUTSONDERWATER
555-1007</fo:block></fo:table-cell><fo:table-cell border-style="solid"
border-width="0.01cm .01cm .01cm .01cm" border-color="white"><fo:block
text-align="center">
                        DISCIPLINE:
014</fo:block></fo:table-cell><fo:table-cell border-style="solid"
border-width="0.01cm .01cm .01cm .01cm" border-color="white"><fo:block
text-align="center">
                        SUB DISCIPLINE:
002</fo:block></fo:table-cell></fo:table-row></fo:table-body></fo:table>
<fo:table font-size="8pt" table-layout="fixed"><fo:table-column
column-width="5.0cm"/><fo:table-co
lumn column-width="5.0cm"/><fo:table-column
column-width="5.0cm"/><fo:table-column
column-width="12.7cm"/><fo:table-body><fo:table-row
height="0.5cm"><fo:table-cell border-style="solid" border-width="0cm 0cm
0c
m 0cm"><fo:block padding="0.1cm 0cm 0cm 0cm" text-align="left">
                    MEMBER DETAILS
.
.
.

(I've cut the last part from this output since it all appears correct.
Except for the dual fo:root tag sets that prevents the FOP from
generating a valid/any PDF file for me.)

 <<200608081650+111.fo>>  <<print_layout.xsl>> 

I've attached the XSL file and the produced .fo file since Microsoft
might be applying formatting to the text that makes my email hard to
read.

Any help and advise that you can offer would be greatly appreciated.

Thanks.


Andries Burger
Snr. C++ Unix Analyst Developer
Digital Healthcare Switch (Pty) Ltd
PO Box 7045, Halfway House, 1685
Tel: 011 265 5527
Fax: 011 265 5470
E-mail: andriesb@switchonline.co.za
Web: www.switchonline.co.za

This e-mail is subject to an e-mail disclaimer. 
To read our e-mail disclaimer notice go to:
http://www.dhsolutions.co.za/disclaimer/email/
Alternatively please contact us on +27 11 265 5400



Re: Problem generating PDF with FOP 0.94

Posted by Chris Bowditch <bo...@hotmail.com>.
Andries Burger wrote:

<snip/>

> a .fo file generated for the layout I want, except that I end up with a 
> double <fo:root> element in the FO file.

<snip/>

> <xsl:key name="htt" match="hospital_item" use="@tariff_type"/>
> 
> <xsl:template match="printspecification">
> 
>     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

Does your XML input contain 2 printspecification elements? I would guess 
that is the most likely reason you end up with 2 fo:root nodes in the FO 
file?

<snip/>

Chris



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org