Publishing Books Using XML Technologies
Dr. Herong Yang, Version 4.01

Example of XSL-FO Document - hello.fo

This section provides a simple XSL-FO (XSL Formatting Objects) document, hello.fo.

Here is my first example of XSL-FO document, hello.fo:

<?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="my_page" margin="0.5in">
   <fo:region-body/>
  </fo:simple-page-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="my_page">
  <fo:flow flow-name="xsl-region-body">
   <fo:block>Hello world!</fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

Note that:

  • XSL-FO document is an XML document with the root element named as "fo:root".
  • All the element names are prefixed with "fo:".
  • Prefix "fo:" is associated with the XML name space: "http://www.w3.org/1999/XSL/Format". This is done by the attribute, "xmlns:xsl" in the root element.
  • Other "fo:" elements are used to provide page formatting information.

The next question is then do we have an application that can process this XSL-FO file to format the embedded information? I tried the following:

  • I don't know how to make IE to work with XSL-FO.
  • I don't know how to make XML Spy to work with XSL-FO. It can be used to edit XSL-FO files. But how to preview the formatted output?
  • I searched the Internet and located FOP from Apache. It can be used to format XSL-FO file into PDF files.

Sections in This Chapter

What Is XSL-FO (XSL Formatting Objects)

Example of XSL-FO Document - hello.fo

Installing Apache FOP - XSL-FO Processor

Formatting XSL-FO Files to Text Files Using FOP

Formatting XSL-FO Files to PDF Files Using FOP

Formatting XML Files to PDF Files with XSLT

Tranforming XML Files with XSLT Stylesheets

Dr. Herong Yang, updated in 2007
Example of XSL-FO Document - hello.fo