Creating a Formatted Document

Creating a Formatted Document

To process and create a formatted document, Ill use James Taubers fop, which has now been donated to the Apache XML Project.

The main fop page is, and currently, you can download fop from The fop package, including documentation, comes zipped , so you have to unzip it. Its implemented as a Java JAR file, fop.jar, and Ill use fop version 0.15 here.

You can use fop from the command line with a Java class that at this writing is org.apache.fop.apps.CommandLine. You need to provide the XML parser you want to use, and Ill use the Xerces Java parser in xerces.jar (which comes with Xalan). Heres how I use fop to convert to planets.pdf with Java in Windows; in this case, Im 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 graphics/ccc.gif 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 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 cant 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, youre going to see all there is to XSLT, and youll also get an introduction to XSL-FO. Now its time to dig into XSLT, starting with the next chapter.

Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
Year: 2005
Pages: 196

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: