1. Quickstart

A XSL-FO file has always the same basic structure. The root element is called <fo:root>. The child elements are a <fo:layout-master-set> element, an optional <fo:declarations> element and at least one <fo:page-sequence> element.

In the <fo:layout-master-set> element the page-specific information is entered, namely the size of the page, the margins, header and footer etc.

With the <fo:declarations> elements colour profiles can be created, but they are optional and rarely used because they are still not supported by the available formatters.

The <fo:page-sequence> elements determine the order in which the pages being defined in the <fo:layout-master-set> element shall appear.

At first, the famous „Hello World“ example shall be introduced in order to demonstrate the minimal page layout of a XSL-FO file.

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">     (1)
   <fo:layout-master-set>                                  (2)
      <fo:simple-page-master master-name="HelloWorld">     (3)   
         <fo:region-body/>                                 (4)
      </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="HelloWorld">        (5)
      <fo:flow flow-name="xsl-region-body">                (6)    
         <fo:block>Hello World!!!</fo:block>               (7)
      </fo:flow>                         
   </fo:page-sequence>
</fo:root>

 

Browser view

Browser view - Hello World

(1) The <fo:root> element is always the root element of a FO document. It contains the namespace declaration, of course obligatory the one for FO itself:
xmlns:fo="http://www.w3.org/1999/XSL/Format"
If you work with the Antenna House Formatter, the namespace for proprietary extensions of Antenna House can also be found in this element.

(2) In the <fo:layout-master-set> element you create the templates for the page layout, the sequence of the page templates and you define the margins and regions of the pages. In this example the element only contains a <fo:simple-page-master>, which is the simplest possible case.

(3) The <fo:simple-page-master> defines the layout of a page. Here specifications regarding height and width of the page can be made and different margins and regions can be defined. In this simple example no specification for the page size or the page margins can be found. These actually required specifications are replaced by the default values of the formatter. The master-name="HelloWorld" attribute gives this page layout a name, so that the default can be called up in the page sequence (<fo:page-sequence>).

Formatter options

Formatter options

(4) The <fo:region-body/> element determines the look of the region in which the current content of the page is located.

(5) <fo:page-sequence> determines the sequence of the above defined page templates and allows the embedding of the actual content into the page sequence. For reference to the page template, the name of this template is assigned to the master-reference attribute, which means in this example the page layout with the name HelloWorld.

(6) The <fo:flow> element indicates that the current content is inserted at this position.

(7) For the formatting of this content at least the embedding into a block element (<fo:block>) is required. If this block exceeds the dimensions of the preset body region, the formatter would perfom the page break on its own and so divide the block between the pages. Instead of a simple block, also more complex block structures such as tables or enumerations can be inserted. In our simple example the block only contains the text Hello World!!!. The actually required specifications for font, font size and so on are replaced by the default values of the formatter.

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de