November 1, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

From XML Data to HTML Tables

  • September 15, 2000
  • By Richard G. Baldwin
  • Send Email »
  • More Articles »

  • Preface
  • Introduction
  • A Sample Program
  • The XML File
  • The XSLT File
  • The Output
  • Complete Program Listings
Preface

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

As of this writing, Microsoft IE5 is the only widely-used web browser that has the ability to render XML documents. IE5 can render XML documents using either CSS (see my personal website) or XSL.

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

xsl:for-each 
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:value-of
and
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 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

theData</font>
. This is where the interesting data about books is actually stored in the XML file.

As you can see, the contents of an element named

theData</font>
consists of three other elements:

  •  title </font>
  •  author </font>
  •  price </font>

What are the contents of these elements? The actual data value associated with that element. Here's some more of the XML file:

 
XML 
R.Baldwin 
$19.60 
 

 

This shows two another element named

theData</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
top</font>
element we saw earlier. Now let's take a look at the XSLT file.





Page 1 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 



Rocket Fuel