XML

Summary

Although I'd love to tell you that this tutorial provided a comprehensive introduction to XSL-FO, the truth is that this lesson really only served as a bare bones introduction to XSL-FO. This is because XSL-FO is one of the most detailed XML technologies you are likely to encounter, and therefore requires much more than an tutorial of your time to truly get to know well. Having said that, this lesson did provide a serviceable introduction to XSL-FO, including the basics of coding XSL-FO documents and converting them to PDF using a handy little tool called FOP. You didn't see the specifics of how to transform a raw XML document to XSL-FO using XSLT but you have the skills to carry out such a transformation based on earlier tutorials. If you find yourself intrigued by the possibilities of using XSL-FO to carefully format XML data for print, I encourage you to further explore XSL-FO on your own. A good place to start is the Wikipedia entry for XSL-FO, which includes several useful links to other XSL-FO resources: http://en.wikipedia.org/wiki/XSL-FO.

Q&A

Are XSL-FO documents usually coded by hand?

No. In fact, XSL-FO is intended to be generated automatically using a transformation language such as XSLT. In a real-world scenario, you would likely use XSLT to automatically transform an XML document into an XSL-FO document, and then use an XSL-FO processor to generate a PDF document automatically. All these steps would take place behind the scenes without any manual involvement. In this lesson I showed you the "brute force" method to creating an XSL-FO document by hand and converting it to PDF so that you could better understand how the XSL-FO language works.

Should I consider switching from CSS to XSL-FO to style my XML documents?

It depends entirely upon your specific circumstances. If you're talking about styling XML documents for the web, the answer is currently a resounding no. There just isn't enough XSL-FO browser support to consider it a viable web technology at the moment. However, if you're talking about styling XML content for print, XSL-FO may very well be a good option as a high-powered replacement for CSS.

Workshop

The Workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.

Quiz

1.

How does XSL-FO relate to CSS?

2.

What are the XSL-FO equivalents of the <div> and <span> tags in HTML?

3.

How do you validate an XSL-FO document?

Quiz Answers

1.

XSL-FO is a functional superset of CSS but an entirely separate technology. Unlike CSS, XSL-FO is used to code entire documents including both content and formatting, whereas CSS is designed purely for applying formatting styles to existing documents. Also unlike CSS, XSL-FO is an XML-based language, whereas CSS relies on its own unique syntax.

2.

The XSL-FO equivalents of the <div> and <span> tags in HTML are <fo:block> and <fo:inline>, respectively.

3.

To validate an XSL-FO document, you currently must reference the RenderX experimental XSL-FO DTD in the document, and then pass the document through the standard W3C Markup Validation Service (http://validator.w3.org/).

Exercises

1.

Develop an XSLT stylesheet to transform an existing XML document into an XSL-FO document.

2.

Feed the newly generated XSL-FO document into FOP to generate a PDF of the resulting formatted XSL-FO document.