Formatting XML Files to PDF Files with XSLT

This section provides an example of formatting an XML file to a PDF file with XSLT stylesheets.

In the previous two examples, the input file is an XSL-FO file which contains the source information mixed with the XSL formatting objects directly. In this example, the source information is stored in an normal XML file, and the XSL formatting objects are mixed with the XSL transformation templates in an XSL file.

So I modified the old hello.xsl into hello_fo.xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 <xsl:template match="p">
<fo:root xmlns:fo="">
  <fo:simple-page-master master-name="my_page" margin="0.5in">
 <fo:page-sequence master-reference="my_page">
  <fo:flow flow-name="xsl-region-body">
   -<xsl:value-of select="."/>-

Note that:

Let's run FOP with the following command:

fop -xml hello_xsl.xml -xsl hello_fo.xsl -pdf hello.pdf

Now if you open the output file, hello.pdf, with Adobe Acrobat Reader, you should see the greeting message, "-Hello world!-", showing at the top left corner of the page. This is perfect.

Table of Contents

 About This Book

 Ideas on Publishing Books using XML

 Overview of hyPub - A Simple XML Publishing Tool

 Writing Book Contents in XHTML Source Files

 Transforming Book Source Files with XSL Technology

 Designing Web Page Layouts with Tables

 Controlling Web Page Appearance with CSS

 Sharing HTML Codes with JavaScript Files

 Generating Web Pages with hyPub

Formatting Printable Documents with XSL-FO

 What Is XSL-FO (XSL Formatting Objects)

 Example of XSL-FO Document -

 Installing Apache FOP - XSL-FO Processor

 Formatting XSL-FO Files to Text Files Using FOP

 Formatting XSL-FO Files to PDF Files Using FOP

Formatting XML Files to PDF Files with XSLT

 Tranforming XML Files with XSLT Stylesheets

 Generating PDF Documents with hyPub

 Areas of Future Improvements


 Full Version in PDF/ePUB