- Introduction
- The Value Proposition
- Applying a Stylesheet to XML
- XML/XSLT in Code
- Detecting Browser Types
- Additional Resources
Applying a Stylesheet to XML
For this example, let's use an XML document that contains the 2001 schedules for several college football teams. We'll make use of XSLT to generate HTML and WML documents in order to display this data to our mobile clients. To download the XML files for this example, click here.
The Extensible Stylesheet Language (XSL) is "a language for expressing stylesheets." It's designed to work hand-in-hand with XML, allowing the developer to traverse the nodes in an XML document (using for each loop functionality), and even express conditional logic for fine-tuned control. An XML parser that supports XSL Transformations (XSLT) must be used to "apply" an XSL stylesheet to an XML document. Such a parser is included with Microsoft's Internet Explorer 5.0+ browsers, but for this example, I'll use the excellent command-line XT implementation from James Clark. Its syntax is as follows:
xt source_document stylesheet_document result_document
The stylesheets for our WML and HTML examples are included in the wml.xsl and html.xsl files, respectively, in the source zip file for this article. Applying these stylesheets to schedule.xsl using XT produces the results shown in Figures 1 and 2.
Figure 1 The WML stylesheet results.
Figure 2 The HTML stylesheet results.