Using XSLT for static web pages

XSLT is published by the World Wide Web Consortium (W3C) and belongs to the family of XML recommendations. XSLT is a technique to transform XML documents into any other formats like HTML, XHTML, WML or just plain text.

In order to help you to understand XSLT and to explain how it works I would need to write a book in a book. Therefore, I would like to recommend another book of an excellent author: "XSLT Programmer's Reference" by Michael Kay, published by Wrox Press. We don't get a funding for this mediation, but this book is a great resource for learning and understanding XSLT.

If we assume, that you know how to deal with XSLT then we can try to find a way how to employ XSLT for static web pages. How can we achieve this high degree of flexibility? Let's start with two simple examples.

First example:

You have created hundreds of XML documents containing the whole information and content of your web site. A single XSLT style sheet is used to transform all documents into HTML 4.01 Strict pages. In order to separate structure from presentation, Cascading Style Sheets (CSS) are applied to the HTML pages. The layout of the HTML pages has been optimised for the latest versions of Opera, Netscape Navigator and Microsoft Internet Explorer, assuming a display with a resolution of 800 * 600 pixels. Your pages are looking really nice in these browsers. Some day, your boss tells you that you shall revise all hundreds of web pages so that the web site is also accessible for web browsers in Personal Digital Assistants (PDA) like Palm, Pocket PC and Psion devices.

Second example:

After you have revised the web site for mobile browsers, your boss asks you to publish the whole web site in XHTML 1.1 Strict and XHTML Basic in parallel. In order to avoid a decrease of the server's performance, the web site shall still serve static web pages.

We have made an assumption that easily leads to a solution: you already use XML documents as the basis for web publishing. If you don't, then you should have a look at the Chapter "Conversion from HTML to XML". XSLT is the solution for both examples even if I don't know an easy to use XSLT editor.

The XML documents only contain the pure content without presentational information. The XML documents may be automatically created out of a single XML document using XSLT (see "A single XML document for the whole web site"). The advantage of a single XML document is the central definition of information blocks that exist in all separate documents. Such an information block might be the footer, for instance. It might contain a copyright statement, an e-mail address and a revision note.

Due to the absence of presentational information in your XML documents and the possibility to restructure the input of the XSLT process to the output, you only need to change the XSLT style sheet to change the layout of all accompanied web pages. All changes have to be made in the XSLT style sheet but not in the XML documents. This applies to:

Therefore, you don't need to care about the layout and the output format in your XML documents for your web pages.

Coming back to the two examples above, the solutions look like these:

First example solution:

Since you already use XML documents and an XSLT style sheet you only need to change the XSLT style sheet according to the requirements of the Web Content Accessibility Guidelines (see Web Content Accessibility Guidelines in practise).

Second example solution:

Even if some tools might exist to convert HTML to XHTML pages like HTML Tidy, I recommend to change the already existing XSLT style sheet to transform the XML documents to XHTML. In order to support both formats, i.e. XHTML 1.1 Strict and XHTML Basic, you should create a second style sheet. The transformation process writes the output files into different directories. A small piece of software on the web server is able to detect the user agent type and knows which user agent shall receive which content format. Depending on the result of this user agent check, the software responds on an HTTP request either with an XHTML 1.1 Strict or XHTML Basic web page reading it out of the appropriate directory.

Copyright © 2001-2003 by Rainer Hillebrand and Thomas Wierlemann