The Hello World VRML File

For our final transformation, we’ll create a VRML file from our XML source document. Here’s the stylesheet that does the trick:

<?xml version="1.0"?>
<!-- vrml-greeting.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>#VRML V2.0 utf8 Shape { geometry ElevationGrid { xDimension 9 zDimension 9 xSpacing 1 zSpacing 1 height [ 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:text>string"</xsl:text> <xsl:value-of select="normalize-space()"/> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.