The Hello World VRML File

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 page 37 We generate our VRML document with the following command: java org.apache.xalan.xslt.Process -in greeting.xml -xsl vrml-greeting.xsl -out greeting.wrl As with our earlier stylesheet, our VRML-generating template is mostly boilerplate, with content from the XML source document added at the appropriate point. The xsl:apply- templates element is replaced with the value of the greeting element. The VRML code here draws a checkerboard, then draws the text from the XML document above it, floating in midair in the center of the document. A couple of views of the VRML version of our XML document are shown in Figure 2-4 . Figure 2-4. Two views of the VRML version of our Hello World document Although we havent discussed any of the specific vocabularies or file formats weve used here, hopefully you understand that you can transform your XML documents into any useful format you can think of. Through the rest of the book, well cover several common tasks you can solve with XSLT, all of which build on the basics weve discussed here.

2.6 Summary

Although our stylesheets here are trivial, they are much simpler than the corresponding procedural code written in Visual Basic, C++, Java, etc. to transform any greeting elements similarly. Weve gone over the basics of what stylesheets are and how they work. page 38 As we go through this book, well demonstrate the incredible range of things you can do in XSLT stylesheets, including: • Using logic, branching, and control statements • Sorting and grouping elements • Linking and cross-referencing elements • Creating master documents that embed other XML documents, then sort, filter, group, and format the combined documents. • Adding new functions to the XSLT stylesheet processor with XSLTs extension mechanism XSLT has an extremely active user community. To see just how active, visit the XSL-List site at http:www.mulberrytech.comxslxsl-listindex.html . Before we dive in to those topics, we need to talk about XPath, the syntax that describes what parts of an XML document we want to transform into all of these different things.