SnTT: Client-side XSLT with Google AJAXSLT
Posted on 7/09/2007 1:35:35 by Tim Tripcony
Over the weekend, I was playing with client-side XSLT in JavaScript, and stumbled upon a great library: AJAXSLT, from "the Google". It allows you to easily apply a stylesheet to XML data that doesn't already include a stylesheet reference. I pulled the library (which consists of 5 .js files) into a Domino database, and extended my recent barebones Ajax library to perform a transform on remote XML using XSL that is also remote. In other words, it Ajaxes the XML, then Ajaxes the XSL, does the transform, and returns the result as a string. This example (which currently works in Firefox and Safari, but not I.E. or Opera... they seem to bomb on the nested Ajax call) shows a transform result being inserted into an empty div (on an otherwise blank HTML page). UPDATE: I made the example page a bit more interactive to make it clearer what's happening, and in what sequence. A button now triggers the load, and the XML/XSL are displayed in textareas as they're retrieved.Why bother? Well, because the largest gap I currently see in the DXL API is an inability to specify a stylesheet path in the output. I'm assuming this was omitted because we can just pipeline a NotesDXLExporter directly to a NotesXSLTransformer... except the transformer in LotusScript is... well, crap. No offense, IBM, but passing it even the most pedestrian of XSL instructions causes it to bomb. Additionally, if we're pulling a ReadViewEntries via Ajax, why send it back to the server for transforming? This approach allows us to pull the XSL from the server as well and then let the client do the work of transforming. In this example, both the XML and the XSL are Page elements; the XML Page uses an embedded view to load the data from the database. The XSL is static, but could reference URL parameters, etc., to provide dynamic transformation options, such as sorting of the data.
You can download the sample database here.