The Hello World PDF File

page 34 fo:repeatable-page-master-alternatives fo:page-sequence-master fo:layout-master-set fo:page-sequence master-name=standard fo:flow flow-name=xsl-region-body fo:block text-align=center font-size=36pt line-height=40pt Hello, World fo:block fo:flow fo:page-sequence fo:root We generated this file of formatting objects with this command: java org.apache.xalan.xslt.Process -in greeting.xml -xsl fo-greeting.xsl -out greeting.fo This lengthy set of tags uses formatting objects to describe the size of the page, the margins, font sizes, line heights, etc., along with the text extracted from our XML source document. Now that we have the formatting objects, we can use the Apache XML Projects FOP tool. After converting the formatting objects to PDF, the PDF file looks like Figure 2-3 . Figure 2-3. PDF version of our Hello World file Heres the command used to convert our file of formatting objects into a PDF file: java org.apache.fop.apps.CommandLine greeting.fo greeting.pdf

2.5.3 The Hello World Java Program

Our last two transformations dont involve XML vocabularies at all; they use XSLT to convert the Hello World document into other formats. Next, well transform our XML source document into the source code for a Java program. When the program is compiled and executed, it prints the message from the XML document to the console. Heres our stylesheet: ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http:www.w3.org1999XSLTransform xsl:output method=text xsl:template match= xsl:text public class Greeting { public static void mainString[] argv { page 35 xsl:text xsl:apply-templates select=greeting xsl:text } } xsl:text xsl:template xsl:template match=greeting xsl:textSystem.out.printlnxsl:text xsl:value-of select=normalize-space xsl:text;xsl:text xsl:template xsl:stylesheet Notice that we used xsl:output method=text to generate text, not markup. Our stylesheet produces these results: public class Greeting { public static void mainString[] argv { System.out.printlnHello, World; } } We generated this Java code with the following command: java org.apache.xalan.xslt.Process -in greeting.xml -xsl java-greeting.xsl -out Greeting.java Notice that the name of the generated file must start with an uppercase letter; Java requires that the name of the file must match the name of the class it contains. Also, this command should be entered on a single line. When executed, our generated Java program looks like this: C:\ java Greeting Hello, World Although generating Java code from an XML document may seem strange, it is actually a common technique. The FOP tool from the Apache XML Project does this; it defines a number of properties in XML, then generates the Java source code to create class definitions and get and set methods for each of those properties.

2.5.4 The Hello World VRML File

For our final transformation, well create a VRML file from our XML source document. Heres the stylesheet that does the trick: ?xml version=1.0? xsl:stylesheet version=1.0 xmlns:xsl=http:www.w3.org1999XSLTransform xsl:output method=text xsl:template match= xsl:textVRML V2.0 utf8 Shape { geometry ElevationGrid { xDimension 9 zDimension 9 xSpacing 1 zSpacing 1 height