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.
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 Tutorial is an in-depth tutorial that covers XSL, XSLT, and XSL-FO in detail, with examples.
- XSL Formatting Objects is a highly-technical tutorial that explains how XSL-FO works and how to use it, with lots of code samples and diagrams to aide understanding.
- What is XSL-FO? is the online version of the first few chapters of Practical Formatting Using XSL-FO by G Ken Holman, an excellent book which is unfortunately no longer in print. (The follow-up, Definitive XSL-FO is still available.)
- Introduction to XSL-FO is a good entry-level explanation of XSL-FO and XML printing.
- A Gentle Introduction to XSL-FO bills itself as "a place to start," and it is. This is a good introduction if you aren't highly technical, don't know a lot about XML, but still need to get a handle on XSL-FO.
- Using XSL-FO, from Sams Teach Yourself XML in 21 Days provides a practical explanation of how XSL-FO is typically used in real life.
- How to Develop Stylesheets Transformations for XML to XSL-FO Transformation (PDF) is an advanced tutorial explaining how to create XSLT stylesheets for converting and printing complex XML documents.
- XSL-FO Tutorial is a 16-part tutorial on XSL-FO, with additional information about Altsoft's proprietary XSL-FO extensions that help print XML directly to PDF.
- XSL-FO Tutorial explains XSL-FO in the context of XML, XSLT, and XPath. This tutorial also includes quizzes, so you can test your knowledge.
- Using XSL-FO to Create Printable Documents explains how to use XSL-FO as a bridge between information stored in a database or reporting system and printable documents.
- XQuery/Generating PDF From XSL-FO Files gives step-by-step practical instructions and code samples for generating PDFs from XML documents using XSL-FO.
- XPubs: XSL-FO for Documentation Formatting is less a tutorial and more a long-form blog post. The more personal approach provides a helpful perspective on the practical advantages and disadvantages of using XSL-FO for print publishing.
Additional Learning Materials
- XML for Creative Content and Page Layout Applications is a white paper advocating the use of XML as a single-source for content that has to be printed and displayed in a number of different contexts, such as a website, a brochure, a store catalog.
- Transforming Word Documents into the XSL-FO Format is an outdated, but still interesting, guide to generating XSL-FO and PDF documents from
- HTML to Formatting Objects (FO) Conversion Guide provides information and templates for converting HTML documents to PDF, using XSL-FO.
- Fosox: Generating XSL Formatting Objects in Python explains how to use Python to generate PDFs from XML documents in Python, using the fosox module.
- Apache FOP is the industry standard print formatter for XSL-FO. It is open source, written in Java, and can produce PDF, PostScript, PCL, AFP, XML, AWT, PNG, and RTF output.
- J4L FO Designer is a WYSIWYG editor for creating and editing XSL-FO files for consumption by Apache FOP or similar print formatters.
- The Oxygen XML Editor has explicit support for XSL-FO editing.
- XMLmind XSL-FO Converter lets you convert from XML or XSL-FO to Microsoft Word, LibreOffice, or OpenOffice formats.
- XML-FO Online Transformations is an online tool that converts XML documents to PDF, using XSL-FO.
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.
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:
- XML Resources and Validators: learn all about XML itself.
- MSXML Introduction and Resources: this will get you going with Microsoft XML Core services (MSXML), which will help you build XML-based applications.
- XPath Introduction and Resources: learn about this XML query language.
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?"