The Hello World Java Program

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 page 36 [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ] colorPerVertex FALSE color Color { color [ 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, 1 1 1, 0 0 0, ] } } } Transform { translation 4.5 1 4 children [ Shape { geometry Text { xsl:text xsl:apply-templates select=greeting xsl:text fontStyle FontStyle { justify MIDDLE style BOLD } } } ] } NavigationInfo { type [EXAMINE,ANY] } Viewpoint { position 4 1 10 } xsl:text xsl:template xsl:template match=greeting xsl:textstringxsl:text xsl:value-of select=normalize-space xsl:textxsl:text xsl:template xsl:stylesheet