XSL-FO Introduction and Resources

HTML was designed primarily to present human-readable content on a screen, in a web browser. XML was designed to store and transfer arbitrarily structured content, primarily for consumption by an application, and frequently for presentation on a screen.

But what are you supposed to do if you want to present your XML not on a screen but on printed paper, in a book, catalog, or brochure? Or as a PDF approximation of those formats?

HTML has virtually no support for paginated content, and non-HTML versions of XML provide no styling information at all. You can use a print-only CSS stylesheet, but that gives only rudimentary control over the print layout.

The solution is a relatively underused standard with huge potential, XSL-FO.

The FO stands for "Formatting Objects," and the standard is a part of XSL — eXtensible Stylesheet Language. The other two parts of the XSL standard are XSLT and XPath.

How Does XSL-FO Work?

If you are used to HTML and CSS, XSL-FO might seem a little weird. One of the most important ideas with HTML+CSS is separation of content from styling. The HTML document contains all the content, ideally without any styling or presentational information; the CSS sheet provides styling and presentation.

XSL-FO is more like a TeX/LaTeX, PostScript or Microsoft Word format — it is a page-layout format that contains both the content and the styling. An XSL-FO (or .fo ) file can be printed directly with a FO Processor.

This doesn't break the separation of concerns, though. Typically, one does not author .fo files directly. The standard method is to produce XML or (X)HTML first, either by hand or programatically (for example, out of a database), and the use XSLT to transform the XML into XSL-FO. XSL-FO can then be consumed by an FO Processor, and turned into printed material for distribution.

XSL-FO, along with the entire XML production chain, is a highly useful tool when you have content that has to be repurposed for different media. The most common use-case is inventory information that has to be displayed in catalogs, brochures, online stores, signage, labels, packaging, and several other formats, all from a single source.

XSL-FO Tutorials

Additional Learning Materials

XSL-FO Tools

Books on XSL-FO

  • XSL-FO (2002), by Dave Pawson, is the standard text on the subject from O'Reilly. It's highly technical, with an emphasis on generating XSL-FO by using XSLT to transform XML documents.
  • XSL Formatting Objects Developer's Handbook (2002), by Doug Lovell, is one of the first, and still one of the best, books to delve specifically into the XSL-FO markup format, instead of simply assuming all XSL-FO would be generated by XSLT transformations.
  • Definitive XSL-FO (2003), by G Ken Holman, is more of a reference book than a tutorial. It explains the W3C specification in detail, covering topics that other XSL-FO guides leave out.

Summary

XSL-FO is one of several XML-related standards that haven't gotten as much attention since HTML and XML diverged. However, it is an extremely useful technology, and there's nothing "legacy" about it. It continues to be in heavy use in enterprise and industrial settings that need to manage content and data across multiple media and publications.


Further Reading and Resources

We have more guides, tutorials, and infographics related to coding and development:

What Code Should You Learn?

Confused about what programming language you should learn to code in? Check out our infographic, What Code Should You Learn? It not only discusses different aspects of the languages, it answers important questions such as, "How much money will I make programming Java for a living?"