An XML-to-HTML Transformation Example

Now let's look at an example of converting an XML document into an HTML document. We will start with the XML document in Listing 9.2, our travel.xml document, and work to produce an HTML-formatted itinerary.

As with any stylesheet, we start with the stylesheet element and Namespace:

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

Next, we specify that the output method is HTML, and we will be indenting again for the sake of readability:

<xsl:output method="html" indent="yes"/> 

The first template will match our root node, and will actually contain all the markup that we will have in the document:

<xsl:template match="/"> 

Now, because we are working with HTML, we can insert ...

Get Special Edition Using XML, Second 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.