This section deals with the procedure followed to integrate the FO code in xsql script.

To obtain more information about the FO language you can access to the page of: Documentation of XSLFO.

To be able to integrate the FO code, it does not work to write directly the tags you want, this is due to that the XSQL language itself is already encoded in tags; therefore when you write a label you want to write literally, it is tried to be interpret as a label and not as a normal text string.

 

1 fo

Example XSQL

The following example is a XSQL script which shows by standard output the string "Hello world!":

Copy
<xsql-script name='main'>
    <body>
        <println>Hello world!</println>
    </body>
</xsql-script>

Example FO

This other code in FO generates a page with the string "Hello world!":

Copy
<?xml version='1.0' encoding='ISO-8859-1' ?>
<fo:root xmlns:fo='http://www.w3.org/1999/XSL/Format'>
<fo:layout-master-set>
   <fo:simple-page-master master-name='Portrait' page-width='21.0cm' page-height='29.7cm' margin-top='0.5cm' margin-bottom='0.5cm' margin-left='0.5cm' margin-right='0.5cm'>
       <fo:region-body margin-bottom='0.5cm' margin-top='1.5cm' />
       <fo:region-before extent='1.5cm' precedence='true' />
       <fo:region-after extent='0.5cm' />
   </fo:simple-page-master>
</fo:layout-master-set>
<!-- START OF THE PAGE -->
    <fo:page-sequence force-page-count='no-force' master-reference='Portrait' initial-page-number='1'>
        <fo:flow flow-name='xsl-region-body'>

               <fo:block>Hello world!</fo:block>

        </fo:flow>
    </fo:page-sequence>
</fo:root>

Wrong example

Seeing the two previous example, if you want to obtain a XSQL script which generates a FO file, you can wrongly conclude tyo write the following code:

Copy
<?xml version='1.0' encoding='ISO-8859-1' ?>
<fo:root xmlns:fo='http://www.w3.org/1999/XSL/Format'>
<fo:layout-master-set>
   <fo:simple-page-master master-name='Portrait' page-width='21.0cm' page-height='29.7cm' margin-top='0.5cm' margin-bottom='0.5cm' margin-left='0.5cm' margin-right='0.5cm'>
       <fo:region-body margin-bottom='0.5cm' margin-top='1.5cm' />
       <fo:region-before extent='1.5cm' precedence='true' />
       <fo:region-after extent='0.5cm' />
   </fo:simple-page-master>
</fo:layout-master-set>
<!-- START OF THE PAGE-->
    <fo:page-sequence force-page-count='no-force' master-reference='Portrait' initial-page-number='1'>
        <fo:flow flow-name='xsl-region-body'>

               <fo:block>Hello world!</fo:block>

        </fo:flow>
    </fo:page-sequence>
</fo:root>

The result of execute the script is evident: syntaxis fail, the labels you want to write literally on the defined output, they are not correctly interpret by the script interpreter. It tries to read "tags" and it does not recognize them and it produces errors.

Correct coding:

Copy
<xsql-script name='main'>
    <body>
        <println>

<fo.xml />
<fo.root>
   <fo.layout-master-set>
       <fo.simple-page-master master-name='Portrait' page-width='21.0cm' page-height='29.7cm' margin-top='0.5cm' margin-bottom='0.5cm' margin-left='0.5cm' margin-right='0.5cm'>
           <fo.region-body margin-bottom='0.5cm' margin-top='1.5cm' />
           <fo.region-before extent='1.5cm' precedence='true' />
           <fo.region-after extent='0.5cm' />
       </fo.simple-page-master>
   </fo.layout-master-set>
    <!-- START SEQUENCE OF PAGES -->
    <fo.page-sequence force-page-count='no-force' master-reference='Portrait' initial-page-number='1'>
        <fo.flow flow-name='xsl-region-body'>
    
               <fo.block>Hello world!</fo.block>
    
        </fo.flow>
    </fo.page-sequence>
</fo.root>                   

        </println>
    </body>
</xsql-script>

The result of execute the script is evident: syntaxis fail, the labels you want to write literally on the defined output, they are not correctly interpret by the script interpreter. It tries to read "tags" and it does not recognize them and it produces errors.

Execution via command line

The result of the execution would be as expected.

It is necessary to use this special tags which would be interpret by the script interpreter and replaced by the corresponding strings at the time of writing the output.

Información

This labels can bring the necessary attributes, for example styles attributes.

Most of the labels listed below makes reference to the generation of tables so this code will be used to exemplify all the labels.

Copy
<xsql-script name='fo_test1'>
    <body>


        <!-- ==================================================== -->
        <!-- Obtain file in variable    .                         -->
        <!-- ==================================================== -->
        <file.writer.open id='out1' encoding='ISO-8859-1'>
             <file name='fo_example1.xml' type='absolute' />
        </file.writer.open>
<!-- Begin of the file which will be generated -->
         <file.writer.println id='out1'><fo.xml />
<fo.root>
    <fo.layout-master-set>
        <fo.simple-page-master master-name='Portrait' page-width='21.0cm' page-height='29.7cm' margin-top='0.5cm'
                                            margin-bottom='0.5cm' margin-left='0.5cm' margin-right='0.5cm'>
            <fo.region-body margin-bottom='0.5cm' margin-top='1.5cm' />
            <fo.region-before extent='1.5cm' precedence='true' />
            <fo.region-after extent='0.5cm' />
        </fo.simple-page-master>
    </fo.layout-master-set>
    <fo.page-sequence force-page-count='no-force' master-reference='Portrait' initial-page-number='1'>
        <fo.flow flow-name='xsl-region-body'>

            <fo.table font-size='14pt' font-family='sans-serif' space-before.optimum='0.05cm' table-layout='fixed'
                                 width='30%'>
                <fo.table-column column-width='1cm' />
                <fo.table-column column-width='1.5cm' />

                <!-- ================================================================ -->
                <!-- Header of the table                                              -->
                <!-- ================================================================ -->
                <fo.table-header>
                    <fo.table-row>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightGreen' font-family='sans-serif'>
                            <fo.block>  City code </fo.block>
                        </fo.table-cell>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightGreen' font-family='sans-serif'>
                            <fo.block>  City </fo.block>
                        </fo.table-cell>
                    </fo.table-row>
                </fo.table-header>


                <!-- ================================================================ -->
                <!--  Body of the table                                               -->
                <!-- ================================================================ -->
                <fo.table-body>
                    <fo.table-row>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightBlue' font-family='sans-serif'>
                            <fo.block>  2 </fo.block>
                        </fo.table-cell>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightBlue' font-family='sans-serif'>
                            <fo.block>  Barcelona </fo.block>
                        </fo.table-cell>
                    </fo.table-row>

                    <fo.table-row>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightBlue' font-family='sans-serif'>
                            <fo.block>  7 </fo.block>
                        </fo.table-cell>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightBlue' font-family='sans-serif'>
                            <fo.block>  Valencia </fo.block>
                        </fo.table-cell>
                    </fo.table-row>

                    <fo.table-row>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightBlue' font-family='sans-serif'>
                            <fo.block>  9 </fo.block>
                        </fo.table-cell>
                        <fo.table-cell padding-top='2.0pt' padding-left='2.0pt' border-style='solid' border-width='0.5pt'
                                                    border-color='black' background-color='lightBlue' font-family='sans-serif'>
                            <fo.block>  Bilbao </fo.block>
                        </fo.table-cell>
                    </fo.table-row>
                </fo.table-body>

            </fo.table>
        </fo.flow>
    </fo.page-sequence>
</fo.root>
<!-- closing of the generated file -->
        </file.writer.println>
        <file.writer.close id='out1' />
    </body>
</xsql-script>

The generated FO file should be converted to obtain a PDF file. This operation can be performed from the desktop tool XSLT processor.