An Ajax Encounter of The Third Kind
The fifth part of Ajax, an optional part, isn’t for the faint of heart. It transcends the “mad scientist stuff” into the realm of the magical, and it is called eXtensible Stylesheet Language for Transformations, or XSLT. In other words, if Ajax really was mad science and it was taught in school, this would be a 400- level course. Why? The reason is that the technology is both relatively new and very, very browser dependent. However, when it works, this method provides an incredible experience for the user.
XSLT
XSLT is an XML-based language that is used to transform XML into other forms. XSLT applies a style sheet (XSLT) as input for an XML document and produces output—in most cases, XHTML or some other form of XML. This XHTML is then displayed on the browser, literally in the “wink of an eye.”
One of the interesting things about XSLT is that, other than the XML being well formed, it really doesn’t make any difference where the XML came from. This leads to some interesting possible sources of XML. For example, as you are probably aware, a database query can return XML. But did you know that an Excel spreadsheet can be saved as XML? XSLT can be used to transform
any XML-derived language, regardless of the source. Listing 2-9 shows a simple Internet Explorer–only web page along the same lines as the earlier examples. By using XSLT and the XMLHttpRequest object to retrieve both the XML and XSLT shown in Listing 2-10, it is extremely flexible. This is because after the initial page is loaded, any conceivable
page can be generated simply by changing the XML and/or the XSLT. Sounds pretty powerful, doesn’t it?