XML

What Is XSL-FO?

Back in Tutorial 11 you learned about the various technologies that enter into the picture with respect to XML stylesheets. You found out that XSL-FO, which stands for XSL Formatting Objects, is the formatting component of the XSL stylesheet technology and is designed to be a functional superset of CSS. This means that XSL-FO contains all of the functionality of CSS, even though it uses its own XML-based syntax. Like its transformation counterpart, XSLT, XSL-FO is implemented as an XML language, which is beneficial for both minimizing the learning curve for XML developers and easing its integration into existing XML tools. Also like XSLT, XSL-FO operates on a tree of XML data, which can either be parsed directly from a document or transformed from a document using XSLT.

XSL-FO began back in the late 1990s when the W3C set out to create a page description language that could be used to format and display XML data. The idea behind this page description language is that it would allow XML developers to completely separate XML content from the details of how that content is rendered on a page for display. To facilitate the translation of raw XML data into a styled format, the W3C also began creating a transformation language. This transformation language became XSLT, while the descriptive formatting language became XSL-FO. However, XSLT caught on much quicker, and ultimately became the standard stylesheet mechanism for XML document processing and transformation. Many web developers now regularly use XSLT in combination with CSS to transform and style XML documents.

This scenario has fallen short of the W3C's initial goal of having XSLT and XSL-FO be the one-two transformation/style punch. The reality is that CSS was already widely supported and understood, so it only made sense for it to represent the first wave of style XML documents. XSL-FO offers everything CSS has to offer and much more, so we may eventually see XSL-FO begin to make its way into web pages at some point in the future. For now, however, XSL-FO is relegated to more of a specialized role in helping to layout and format very specific types of print documents.

Comparisons are often made between XSL-FO and CSS, and for the most part they are valid. One critical distinction between the two technologies is that CSS styles are always attached to an existing document tree, whereas XSL-FO establishes its own document structure. In other words, you apply CSS styles to XML data, whereas XSL-FO represents a complete merger of data and styles. In practice, XML data is typically still maintained separately from its XSLT stylesheet, which is then used to combine the data and XSL-FO styles into a complete XSL-FO document.

The good news is that aside from web browsers, there is actually a great deal of support for XSL-FO in back-end XML development tools. You learn about one such tool later in this lesson when you find out how to convert XSL-FO documents to PDF documents.