Using XSL Formatting Objects - Processing a document
(Page 3 of 4 )
Of course, by itself, the document is worth nothing. Recall that a processor such as Apache FOP is needed to process the document into a more meaningful format. Let's make our "Hello world" example into a PDF document. Go ahead and download the latest version of Apache FOP:
http://xmlgraphics.apache.org/fop
Converting the raw XSL-FO file into a PDF file is incredibly simple. Simply run the following command; a PDF file named helloworld.pdf will be created:
fop helloworld.fo helloworld.png
The document can be processed in a number of other ways as well. We could, for example, output a file in rich text format:
fop helloworld.fo -rtf helloworld.rtf
Or we could generate an image:
fop helloworld.fo -png helloworld.png
To view a more complete list of possible output formats, check the documentation or type "fop" without any arguments at the command line. Just keep in mind that some of these formats won't take advantage of all the functionality that XSL-FO provides. A PDF file is a lot more suited to paged data than a PNG image.
One of the most useful things to do, however, is to immediately display the resulting document on the screen. This can easily be done using Apache FOP:
fop helloworld.fo -awt
The processor isn't limited to simple FO-to-output operations. Recall that formatting objects were designed to be used with XSLT and XML data. It's possible to use another program such as Saxon to generate formatting objects from an XML document and an XSLT stylesheet, but Apache FOP can actually combine these steps. That is, you can specify an XML file and an XSLT stylesheet, and it can output a PDF file. We'll take a look at this later.
Next: Page masters >>
More XML Articles
More By Peyton McCullough