Search:
Quick Links
Text Size: normal big huge
International Webmasters Association W3C XHTML 1.0 Valid
Articles

The Appeal of XSL

By: Tom Wheeler

The Web is made possible by technology, and sometimes it seems that the pace of development is so rapid that it's hard to keep up with what's new. A developer often has to pick and choose which technologies to investigate, and with all the hype surrounding "the next big thing" it can be hard to know what's really useful.

If you've learned XML, you might have initially thought, "This is so simple; what's the big deal?" It may have hit you later that the simplicity — the elegance — of XML is what makes it popular. Like any technology, XML is not perfect for every situation, but for instances where an open and flexible way of representing data is required, it's often an excellent choice. And it's becoming more popular all the time as it forms an integral piece of many development platforms including Sun Microsystem's Java and Microsoft's .NET.

One of the reasons that XML maintains its simplcity is because it doesn't try to do everything; it just tries to do one thing (represent data) well. It leaves everything else, such as how to display that data up to other standards. There are currently two ways with which you can stylize XML data — Cascading Style Sheets (CSS) and XSL Transformation (XSLT).

CSS with XML works the same as CSS with HTML; you simply describe what formatting attributes (such as font and color) you want to apply to specific elements. While XSL is a more complex language, it's also much more powerful.

As the name would imply, XSLT allows you to transform your data, based on arbitrary conditions. For example, while the content given page of a Web site will remain the same, you could render it differently based on the browser used to visit your site. You could have a stylesheet that displays all the flashiest tricks of DHTML while using a different stylesheet maintains compatibility with the oldest and most feeble of browsers. And to be clear, this isn't like the old days where you would have to create alternate versions of every page on your site for each browser (a maintenance nightmare). You'd just have to create a single stylesheet that knows how to display the data of any page for a particular browser.

While the flexibility afforded by rendering data differently for browser support is appealing, XSL is capable of much more. Unlike HTML, It's a full-fledged programming language that can perform calculations and use conditional logic. This makes it possible to have a complete set of XML data, but make it available in different formats for different audiences. For example, you could show part of an article (like the summary) to the public, but only make the entire document available to paying customers. You could also provide that same data in HTML, plain text or PDF depending on user preferences, all from a single piece of content. This reduces maintenance costs while providing increased flexibility.

The combination of XML and XSLT provides a powerful tool to developers. Since XSL is a standard endorsed by the W3C, there are libraries and tools are available for most modern programming languages, including Java, C++, ColdFusion, Python and Perl.

Copyright © 2004 Tom Wheeler