From XML Data to HTML Tables
- A Sample Program
- The XML File
- The XSLT File
- The Output
- Complete Program Listings
I have authored numerous online articles on XML. These articles cover the range from introductory to advanced topics. I maintain a consolidated index of hyperlinks to all of my XML articles at my personal website so that you can access earlier articles from there.Rendering XML documents
This is one in a series of articles that discuss the use of XSL for the rendering of XML documents, with particular emphasis on the use of IE5 for that purpose.Introduction
In a previous article, I showed you how to use the
processing element to loop through and display the contents of a series of XML elements of the same type. I also showed you how to use a couple of other processing elements as well:
The program was simple. In order to keep the program as simple as possible, I minimized the use of HTML code. As a result, the program didn't do anything useful.Make it useful
Now I am going to go back and upgrade that program into one that could be useful. In particular, I am going to loop through a series of XML elements and cause the contents of those elements to be deposited in an HTML table.A Sample Program
In this lesson, I will develop the XML code representing a small database of information on books. In addition, I will develop the corresponding XSLT code required to process that database.
I will also show you how to use IE5 to transform the data in the XML database to HTML according to the XSLT. When you load the XML file into IE5, the XML will be converted into an HTML table and displayed in the browser window. Alternately, you can load the XML file and the XSLT file into the XSL Debugger discussed in an earlier lesson and get essentially the same result.This example is based on XSLT information available at the W3C and on IE5 information available at Microsoft. The XML File
The XML file is named XSL003.xml. I am purposely skipping the preliminary material at the top, such as the xml version tag and the xml-stylesheet tag. You have seen that code before, and there is nothing new there.
The first element is simply:
Following that element are the data elements:
Java R.Baldwin $9.95
The XML file shows the first of several elements named As you can see, the contents of an element named What are the contents of these elements? The actual data value associated with that element. Here's some more of the XML file: This shows two another element named
. This is where the interesting data about books is actually stored in the XML file.
consists of three other elements:
. A simple database like this could potentially contain hundreds, or even thousands of such entries. This code also shows the end tag for the
element we saw earlier. Now let's take a look at the XSLT file.
Page 1 of 3
As you can see, the contents of an element named
What are the contents of these elements? The actual data value associated with that element. Here's some more of the XML file:
This shows two another element named