Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

XSL-FO - Extensible Stylesheet Language Formatting Objects

An introduction to XSL:FO

By Jennifer Kyrnin, About.com

In order to process an XSL stylesheet, a stylesheet processor accepts data in XML and an XSL stylesheet to define the presentation of that XML. But there are two parts of the presentation:

  1. Construction of a final document, called a results tree - defining how the document will be used, for instance in print, on the Web, on a handheld device, and so on
  2. Interpretation of that results tree to produce formatted results - defining the look and feel of the document

The results tree is generated by XSLT, and is outside the scope of this article. This article is going to talk about XSL:FO - the formatting objects that allow you to interpret your XML and produce formatted results.

Look at an XSL:FO Document

(Note: line numbers included for reference, they are not a part of the document.)

1  <?xml version="1.0" encoding="iso-8859-1"?>
2  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
3  <fo:layout-master-set>
4  <fo:simple-page-master master-name="basic_page">
5  <fo:region-body margin="1in"/>
6  </fo:simple-page-master>
7  </fo:layout-master-set>
8  <fo:page-sequence master-reference="basic_page">
9  <fo:flow flow-name="xsl-region-body">
10 <fo:block font-family="Arial" font-size="14pt"> 11 Hello, world! 12 </fo:block>
13 </fo:flow>
14 </fo:page-sequence>
15 </fo:root>

Lines 1 and 2 declare that this is an XML document. Line 1 is the XML declaration and line 2 is the root element with the namespace listed. Line 3 is the wrapper around all masters used in the document. I'm using a simple-page-master (line4) to define the geometry of the page and give it a name. My basic_page will have a margin of 1 inch on all sides.

Once you've defined the master pages, you can start defining the sequences of your pages and how they will look. Since I only have one page in my sample document, I only need to define the sequence of one page (line 8). First you enclose all text in a flow element. Since I only defined one flow in my master, that's the one I should use - "xsl-region-body" (line 9). Then the fun begins.

I place all my text inside block elements. Text cannot be placed into a flow without an enclosing element. I'm using the font-family and font-size attributes of the block element to format my text.

What to Do with an XSL:FO Document

Once you have written an XSL:FO document, what can you do with it? Well, you could open it in a Web browser, but it would just display as XML. Instead, you need to get an XSL formatter and convert your XSL document into a formatted masterpiece.

Explore Web Design / HTML

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Web Design Articles R-Z
  6. Web Design/HTML Articles X
  7. XSL-FO - Extensible Stylesheet Language Formatting Objects

©2009 About.com, a part of The New York Times Company.

All rights reserved.