Extensible Stylesheet Language Formatting Objects - Introduction to XSLFO

XSLFO is Extensible Stylesheet Language Formatting Objects which is an XML document by itself. This is a language for formatting XML data and is a W3C recommendation. This is interchangeably also called as XSL.


The XSLFO documents are more complex when compared to XSLT. The XSLFO documents contain formatting information that is used to format the XML data in the desired format. For example, the pagination, layout and other formats required for the XML documents are found in the XSLFO document. Since XSLFO documents are more complex, usually XML documents are initially transformed into formatting documents and then finally using some tools available, the XSLFO document is converted to give an output format.

The XSLFO documents will usually have a file extension of .fo or .fob. To make it easier to open them in the XML editors some developers used to have these file’s extension as .xml itself. But it is a practice to have their extension as .fo or .fob. The code given below is an example of an XSLFO document.

<?xml version="1.0" encoding="utf-8"?>

<fo:simple-page-master master-name="MasterMain">
<!-- The page template can be given here -->


The XSLFO document has a root element called the <fo:root> which is the starting element of the document. Since this is an xml document, it is proper to start the document with the xml declaration. You can specify the xml namespace for the xslfo document in the root node itself, i.e., in the <fo:root> itself as an attribute. After this root element you have the layout-master-set element which contains the simle-page-master element. Within the layout-master-set element you can have any no of simple-page-master elements. These simple-page-master elements contain the page template that is required to give the desired output to the xml data.

The simple-page-master will have an master-name attribute which identifies the simple-page-master. It contains the page formatting details in the form of attributes. The code given below gives a sample of the simple-page-master with those attributes.

<fo:simple-page-master master-name="MasterMain"

<!-- The page template can be given here -->


The attributes that are given in the above code are page-height, page-width, margin-left, margin-right, margin-top, and margin-bottom which are specified in cms. These attributes are self describing and does not need explanations.

Apart from the layout-master-set in the root element, there is another element called the page-sequence which contains the page contents in it. The page sequence has an attribute called master-reference which refers to the master-name of any page template. The following code gives the structure of the page-sequence element.

<fo:page-sequence master-reference="MasterMain">
<!— Content of the page is given here -->

The formatting model of XSLFO defines different areas for the output of the document. The output is split into different areas. The areas are: Pages, Regions, Block Areas, Line Areas, and Inline Areas. The output of any document in this formatting model has many pages. Pages are split into Regions and Regions are split into Block Areas. A Block Area can have other block areas or Line Areas. Line Areas contain Inline Areas, which contain the actual text or image of the document.

<fo:page-sequence master-reference="MasterMain">
<fo:flow flow-name="MainFlow">
<!—Page Content is given here -->

The code given above gives the actual structure, where the page content is given. Within the page-sequence element, there is an element called the flow. This flow element has a block element which contains the actual content that comes in the page.

<fo:block font-size="20pt">
Block Heading
<fo:inline font-style="italic">
<fo:inline font-weight="bold">Content Here...</fo:inline>

A <fo:block> element can also have many <fo:inline> elements within them as given in the above code. It is also possible that the inline elements can contain other inline elements. As we have said earlier the block elements can also contain other block elements and the structure of the document can be more complex. XSLT is combined with XSLFO to produce quality and fast output. An XSLFO document needs programs to convert the document into a quality ouput like pdf document or html document. There are many software available for this purpose. Softwares like XSL Formatter, Xinc, and Scriptura are used to convert the XSLFO documents to other types of document outputs. Software such as XML2PDF (Microsoft .Net Framework based engine) and Sigmagis are also used for the conversion of XSLFO documents.


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.


Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.


FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.



Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.



Add to My Yahoo!

Visit XML Training Material Guide Homepage



Copyright - © 2004 - 2017 - All Rights Reserved.