- Events or Trees?
- The Data Source
- The Problem Definition
- The Solution: Using Stylesheets with XSLT
- The Source Code
- Conclusion
The Problem Definition
Given the XML data described in Listing 1, we want to regenerate this data as HTML. Earlier I mentioned bridging the gap between legacy and modern software systems; this is an example of such a bridge at the data level. We want to be able to see the contents of Listing 1 as illustrated in Listing 2.
Listing 2 XML data regenerated as HTML
<html> <body> <nodedata align="center"> <h1>Contact: Stephen Morris</h1> <h2>Email: stephenbjm@yahoo.com</h2> <h2>Telephone: 1800 512 9999</h2> <h2>Sysnname: LER A</h2> <h2>IP-capable: Yes</h2> <h2>MPLS-capable: Yes</h2> <h2>LastDiscovery: 1 January 2005</h2> <h2>Location: Europe</h2> </nodedata> </body> </html>
Listing 2 can be viewed in a browser if required. The tags <h1> and <h2> serve as heading levels in standard HTML. (Interestingly, some technical web sites require authors to submit work only in HTML format!)
Notice a subtle difference between the data in Listings 1 and 2: The HTML tags include additional information about the element. For example the <h1> tag of Listing 2 includes the text Contact: . This is achieved using a stylesheet during the transformation from XML into HTML.