- XSLT Overview
- Start with the Data
- From XML to HTML
- XSLT
- Summary
- References
Start with the Data
Let’s begin by looking at our XML data. Listing 1 shows our top-level element, books, containing a collection of book elements, each with two child elements, title and author. To make things interesting, isbn is set up as an attribute of book.
Listing 1 XML with ZwiftBooks bestsellers.
<?xml version="1.0"?> <!-- ZwiftBooks List of Popular Books --> <books> <book isbn="0-321-33019-6"> <title>Garage Band 2</title> <author> <lname>Plummer</lname> <fname>Mary</fname> </author> </book> <book isbn="0-13-185586-7"> <title>HTML and CSS</title> <author> <lname>Holzschlag</lname> <fname>Molly</fname> </author> </book> <book isbn="0-596-00764-7"> <title>XML in a Nutshell</title> <author> <lname>Harold</lname> <fname>Rusty</fname> </author> </book> <book isbn="0-596-00053-7"> <title>XSLT</title> <author> <lname>Tidwell</lname> <fname>Doug</fname> </author> </book> <book isbn="0-201-30983-1"> <title>C++ FAQs</title> <author> <lname>Cline</lname> <fname>Marshall</fname> </author> </book> </books>
When working with XSLT, it’s useful to visualize the tree structure of our XML document, as shown in Figure 2. Notice that the element data appears at the bottom, on the "leaves" of the tree. Attribute data, on the other hand, is associated with the element where the attribute is declared. In our example, the book element serves as the parent of the isbn attribute.
Figure 2 The tree presentation of the XML document in Listing 1.