Publishing with XML - Herong's Tutorial Examples - v4.02, by Dr. Herong Yang
Tranforming XML Files with XSLT Stylesheets
This section provides a simple XSL-FO (XSL Formatting Objects) document, hello.fo.
The FOP package also contains another XML tool called "xalan". It can be used to transform an XML file based the transformation templates defined in an XSL file. To run "xalan", create a batch file, xalan.bat, with the following command:
java -cp \local\fop-0.20.5rc2\lib\xercesImpl-2.2.1.jar; \local\fop-0.20.5rc2\lib\xalan-2.4.1.jar org.apache.xalan.xslt.Process %1 %2 %3 %4 %5 %6
Now let's run "xalan" to transform hello_xsl.xml with hello_fo.xml:
xalan -in hello_xsl.xml -xsl hello_fo.xsl -out hello.out
Open hello.out with a text editor, you will see:
<?xml version="1.0" encoding="UTF-8"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout... -Hello world!- </fo:block></fo:flow></fo:page-sequence></fo:root>
This is exactly what I expected. The output generated from the transformation template contains the formatting objects and information from the source XML file. Note that the format is not well maintained during the transformation. The first line is too long, I have to truncate it.
So if you have some data organized in an XML file, you can write an XSL file with transformation templates to re-organize the data. In the same XSL file, you can also put some formatting objects to format the re-organized data into a pintable format.
You can finish the transformation and formatting process in two steps:
Table of Contents