Target format print

Figure 743. Basic FO introduction Slide presentation

exercise No. 9

Creating a desired FO target example

Q:

This exercise serves as a prerequisite for generating printed output for XML instances based on your simplified <book> schema: As with the HTML target format it is a good idea to have a running example before creating a corresponding XSL file in the subsequent exercise Transforming <book> instances to PDF .

  1. Create a FO skeleton file book_intended.fo:

    <?xml version="1.0" encoding="UTF-8"?>
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
        <fo:layout-master-set>
            <!-- Define a simple page layout -->
            <fo:simple-page-master master-name="simplePageLayout"
                page-width="60mm"   page-height="100mm">
                <fo:region-body/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <!-- Print a set of pages using the previously defined layout -->
        <fo:page-sequence master-reference="simplePageLayout">
            <fo:flow flow-name="xsl-region-body">
                <fo:block>Introducing Java</fo:block>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
  2. Configure OxygenXML to transform book_intended.fo to book_intended.pdf.

  3. Extend book_intended.fo by:

    • Modify the title heading corresponding to <book>/<title> by supplying appropriate style attributes like e.g. font-size.

    • Add FO constructs corresponding to your elements <chapter>, <paragraph>, <itemizedlist> and <listitem> in your sample document. Your final result should result in a satisfying PDF.

Tip

Read the Lists section regarding your <itemizedlist> element.

exercise No. 10

Transforming <book> instances to PDF

Q:

Write an XSL stylesheet converting <book> instances into PDF. Start from the following skeleton file book2fo.xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/book">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="simplePageLayout"
                    page-width="294mm" page-height="210mm" margin="5mm">
                    <fo:region-body margin="15mm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="simplePageLayout">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="xx-large" font-weight="bold">
                        <xsl:value-of select="title"/>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

Take your result from exercise Creating a desired FO target example as a reference.