views:

30

answers:

1

The short version: Is it possible to switch to alternate XSL stylesheets in the browser, a la CSS stylesheet switching?

The long version:

I've always admired the CSS Zen Garden; it excellently showcases the power and flexibility of stylesheets. However, it also shines a light on one of the great weaknesses of CSS: a quick View Source reveals a wealth of tags with no semantic value, which exist solely to give the stylesheet room to work. (Paragraph-wrapping <span>s, onion-layering, the half-dozen "extraDiv"s at the bottom…)

I've been playing around with the idea of using XSLT to work around this; starting with a semantically clean XHTML file and using XSLT to inject both the CSS stylesheet and any non-semantic markup required by it. However, there seems to be little practical value in doing so unless the XSL stylesheets can be switched in the browser in a similar manner to switching CSS stylesheets. Otherwise, each different stylesheet will cause a cache miss and you might as well do the processing on the server side.

Browser support for the <?xml-stylesheet?> PI seems decent, but I haven't found anyway to trigger alternate stylesheets via JavaScript or browser UI (FF, Chrome). Has anyone else tried this?

Edit: Oh, and browser-specific solutions are welcome; this is just an experiment, not something I expect to use on a live site anytime soon! ;-)

+1  A: 

At least for IE you can do the transform manually in JScript and write the contents of the transform to the document. See something like this.

This is similar for FF.

tyranid
I hadn't thought about it from the angle of manual transformations. Thanks for the links!
Ben Blank