Creating a Formatted Document

Creating a Formatted Document

To process planets.fo 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 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. 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 planets.fo 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 planets.fo 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 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.
graphics/01fig08.gif

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
EAN: N/A
Year: 2005
Pages: 196

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net