开发者

Dynamically switching XSLT stylesheets in the browser?

开发者 https://www.devze.com 2022-12-21 14:35 出处:网络
The short version: Is it possible to switch to alternate XSL stylesheets in the browser, a la CSS stylesheet switching?

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 se开发者_StackOverflow社区rver 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! ;-)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号