Experimenting with XSLT to transform XHTML into...XHTML

Admittedly, I'm a novice when it comes to XSLT.

However, this does not stop me from playing around with the technology for my own evil purposes...

I've seen quite a number of excellent XSLT examples that demonstrate how the technology can be used to transform one type of XML format into another - Atom into XHTML, for instance.

Here's an off the wall idea though: why not use it to change a simple XHTML file like this one into...another XHTML file? Yes, I know, not earth-shattering, but it was a weird thought that I needed to get out of my system.

If you have a browser capable of client-side XSL transformations (IE6.0 or any Gecko-based one will do), you can view this simple page as it appears after being processed through this XSLT.

Technical side note

All I'm doing to trigger the transformation is adding <?xml-stylesheet type="text/xsl" href="transformer.xsl"?> via a small PHP switcher that looks for the presence of the transform GET variable.

View the source of the regular file, and compare it with the source of the transformed one. For added fun, if you use Mozilla or Firefox, load up the transformed file in the DOM inspector to see what the transformation really created.

Putting my accessibility hat on, it may also be worth noting: tests using JAWS 4.01 and IE6 indicate that the screenreader is perfectly happy working on the transformed version of the page (i.e. it reads the result after the transformation).

Originally, this page (and the transformed version) were sent to the browser as application/xhtml+xml. IE, however, doesn't like that, and prompts for download.

My initial thought was to then send both versions as application/xhtml+xml for browsers that support it, and simple text/html for others. Unfortunately, this prevents IE from applying the client-side transformation in the transformed file.

Third idea was to just send both versions as application/xml. Once again, IE didn't play ball, refusing to then display the regular XHTML file as a web page.

Final, slightly kludged, solution - involving some server-side scripting: