- Chapter 1: Essential XSLT
- A Little Background
- XML Documents
- What Does XML Look Like in a Browser?
- XSLT Transformations
- Making an XSLT Transformation Happen
- Using Standalone XSLT Processors
- Using Browsers to Transform XML Documents
- XSLT Transformations on Web Servers
- XML-to-XHTML Transformations
- XSLT Resources
- XSL Formatting Objects: XSL-FO
- XSL-FO Resources
- Formatting an XML Document
- The XSLT Stylesheet
- Transforming a Document into FormattingObject Form
- Creating a Formatted Document
Creating a Formatted Document
To process planets.fo and create a formatted document, I'll use James Tauber's fop, which has now been donated to the Apache XML Project.
The main fop page is http://xml.apache.org/fop, and currently, you can download fop from http://xml.apache.org/fop/download.html. The fop package, including documentation, comes zipped, so you have to unzip it. It's implemented as a Java JAR file, fop.jar, and I'll use fop version 0.15 here.
You can use fop from the command line with a Java class that at thiswriting is org.apache.fop.apps.CommandLine. You need to provide theXML parser you want to use, and I'll use the Xerces Java parser in xerces.jar (which comes with Xalan). Here's how I use fop to convert planets.fo to planets.pdf with Java in Windows; in this case, I'm specifying the classpath with the -cp switch to include xerces.jar, as well as two necessary JAR files that come with the fop downloadfop.jar and w3c.jar. (This example assumes that fop.jar, xerces.jar, and w3c.jar are all in C:\planetsif not, you can specify their full paths.)
C:\planets>java -cp fop.jar;xerces.jar;w3c.jar _org.apache.fop.apps.CommandLine planets.fo planets.pdf
You can use the Adobe Acrobat PDF reader to see the resulting file, planets. pdf, as shown in Figure 1.8. (You can get Acrobat PDF Reader for free at http://www.adobe.com/products/acrobat/readermain.html.) The planets.xml document appears in that figure formatted as specified in the planetsPDF.xsl stylesheet.
Figure 1.8 A PDF document created with formatting objects.
The PDF format is a good one for formatting object output, although it has some limitationsfor example, it can't handle dynamic tables that can expand or collapse at the click of a mouse, or interactive multiple-target links, both of which are part of the formatting objects specification. Although there is little support in any major browser for XSL-FO today, it will most likely be supported in browsers one day.
That completes your overview. In this book, you're going to see all there is to XSLT, and you'll also get an introduction to XSL-FO. Now it's time to dig into XSLT, starting with the next chapter.