Contents | < What is XSL-FO | Paragraphs >

Hello World

Here is the traditional Hello World, XSL-FO style:

<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" >Œ
    <fo:layout-master-set>
        <fo:simple-page-master master-name="LetterPage" page-width="8.5in"  
                               page-height="11in" >Ž
            <fo:region-body region-name="PageBody" margin="0.7in"/>
        </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="LetterPage">
        <fo:flow flow-name="PageBody">
            <fo:block>Hello World</fo:block> 
        </fo:flow>
    </fo:page-sequence>
</fo:root>
For the complete source code for this code example see "Tutorial/Hello World.fo" located under XML Documents Samples/Tutorial folder.

There are several things to notice:

Œ Any XML document must have only one root, and XSL- FO makes no exception. The root element for an XSL-FO document is fo:root.

The word "fo" before column character ":" is called a namespace prefix. An XML namespace is collection of names identified by an unique URL. It's main role is to avoid collisions when a single XML document contains elements and attributes defined by multiple software modules. The "fo" namespace prefix is linked with an unique URL, in this case "http://www.w3.org/1999/XSL/Format" using xmlns attribute. This syntax is based on W3C XML Namespace Spec.

 Ž The pages structure is defined using fo:layout-master-set; more about this in the chapter Pagination. For now, is enough to say that it declares one type of page, 11.5 x 8 inches (US Letter).

 The "Hello World" paragraph is added into the page.

The result of rendering should be identical with the following figure.

Figure 1


To convert this document into PDF, you can use XF Designer 2004. Open the document and generate the PDF from the tools menu. Or you can use render.exe, a console program located in "C:\Program Files\Ecrion Software\XF Rendering Server 2008\bin". The command line is:

render.exe -fo HelloWorld.fo -pdf C:\Temp\HelloWorld.pdf
The command line flag -pdf is optional; if not present render will generate a PDF file with a name identical with the input file's name and .pdf extension.

 

Contents | < What is XSL-FO | Paragraphs >