The Syntax

Now that you have a conceptual understanding of the pieces of the XML transformation puzzle, let’s begin to assemble these pieces into something meaningful. We will begin with our original XML file representing a portion of this book’s table of contents. We would like to output this XML file in HTML, formatted to our liking. This is an extremely common task in Java applications today, and although we will only perform simple formatting on this file, the possibilities for the resultant HTML’s complexity are only bounded by our knowledge and skill at XSLT. As we move step by step through the process of creating a stylesheet to apply to our XML, we will cover the most common constructs within XSLT and look at how they are often applied in XML applications.

Because this chapter is an introduction to XSLT, we will not look at the more complex transformations from one XML format to another. These transformations, while common in large business-to-business applications, are often more dependent upon application and business rules specific to a company. We will later touch on these types of XML transformations in our chapter on XML-RPC and XML for data storage, so if you are looking to use XML for data transport more than for presentation, we will not leave you out. The actual constructs used in transformation will be identical as well; only the resulting output will be different. With that understanding, let’s generate some HTML!

XSL Is XML

The first task any XSL stylesheet must ...

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