From XML Data to HTML Tables
- Preface
- Introduction
- 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.
IntroductionIn 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: xsl:for-each
and xsl:value-of
xsl:template
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 usefulNow 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 ProgramIn 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 FileThe 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. theData</font>
consists of three other elements:theData</font>
title </font>
author </font>
price </font>
. A simple database like this could potentially contain hundreds, or even thousands of such entries. This code also shows the end tag for the theData</font>
element we saw earlier. Now let's take a look at the XSLT file.
top</font>
Page 1 of 3
Comment and Contribute
