Transforming an XML File from Within a Java Program

Now that we're getting more comfortable with Java, let's do something really useful: create our product pages. We'll start by using a Java program to create XHTML files that traditional browsers can read even if they don't understand XML.

Creating the Style Sheet

The first thing that we need to do is to create the style sheet that we'll use for transforming the product page. Let's start by getting the basic formatting down, as in Listing 4.16.

Listing 4.16. productpage.xsl: The Overall Style Sheet
 0: <?xml version="1.0"?> 1: <xsl:stylesheet version="1.0" 2: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 3: 4: <xsl:include href="topinclude.xsl"/> 5: 6: <xsl:template match="//product"> 7: ...

Get XML and Java™ from scratch 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.