XSL-FO Tutorials - Herong's Tutorial Examples - v2.25, by Herong Yang
"fop -xml -xsl" - Transformation and Formatting
This section provides a tutorial on how to run the 'fop -xml -xsl' command to process an XML data file with formatting object properties specified in an XSLT file into different presentation formats.
Apache™ FOP can also be used to perform the full 2-step process as recommended by the W3C XSL 1.1 specification - Transformation and Formatting with a single command "fop -xml ... -xsl".
Here are some variations of the "fop -xml ... -xsl" command option:
fop -xml xxx.xml -xsl xxx.xsl -pdf xxx.pdf Transform xxx.xml with xxx.xsl and format the result into a PDF file: xxx.pdf fop -xml xxx.xml -xsl xxx.xsl -awt Transform xxx.xml with xxx.xsl and format the result into a new window on the screen fop -xml xxx.xml -xsl xxx.xsl -png xxx.png Transform xxx.xml with xxx.xsl and format the result into PNG files, xxx?.png, one per page
To test the "fop -xml ... -xsl" command option, let's create the following XML file, hello.xml, that contains only data content:
<?xml version="1.1"?> <p>Hello world!</p>
Then create an XSLT file, hello-fo.xsl, that contains a transformation template to convert data into formatting objects:
<?xml version="1.1" encoding="utf-8"?> <xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="my_page" margin="0.5in"> <fo:region-body/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="my_page"> <fo:flow flow-name="xsl-region-body"> <fo:block><xsl:value-of select="p"/></fo:block> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> </xsl:stylesheet>
Next, run following commands:
herong> fop -xml hello.xml -xsl hello-fo.xsl -pdf hello.pdf 10:40:44 AM org.apache.fop.events.LoggingEventListener processEvent INFO: Rendered page #1. herong> dir hello*.* 675 hello-fo.xsl 5,172 hello.pdf 42 hello.xml
Now open hello.pdf with Adobe Acrobat Reader. You will see the text "Hello world!" nicely formatted on page #1 with a 0.5 inch margin as specified in the XSLT file.
Table of Contents
►Apache™ FOP (Formatting Objects Processor)
FOP Download and Installation on Windows
FOP Installation Verification on Windows
FOP Download and Installation on macOS
FOP Installation Verification on macOS
"fop -fo" - Formatting XSL-FO Files
►"fop -xml -xsl" - Transformation and Formatting
"fop -xml -xsl -foout" - XSLT Transformations
XSL-FO Document Basics and Examples
Block-Level Formatting Objects
Inline-Level Formatting Objects
Including Graphics in XSL-FO document
Floating Blocks - "float" and "footnote"
Hyperlinks, Table of Contents and Indexes
Headers and Footers using "static-content"
Font Attributes and Font Families
Apache FOP Font Configurations