灵感的来临,没有任何预兆;灵感的消失,也不会有告别仪式;用文字记下她们吧,让灵感永存……

尝试 XML + XSL

davies 发表于 2005 年 04 月 22 日

下午测试了一下 XML + XSL ,效果还是不错的,偷来 Spaces 的 XSL 文件,稍微修改了一下,用在我自己的 rss.xml 上,就可以得到比较好的显示效果。

这种方案需要浏览器的支持,它将生成 HTML 页面往后推给了浏览器,增加了浏览器渲染网页的负担,自然降低对了服务器端的负荷。一般 XSL 都是固定不变的,变的只是 XML 中的内容。而 XML 中主要是由日志构成,如果日志的存储格式就是 XML ,并且按照 RSS 的标准,那只需要将某些需要的日志的 XML 文件直接连接到一起就可以得到输出了。目前大家用的电脑都相对配置高,而且访问是分散的,将这部分计算量留到客户端进行是个不错的选择。

比较郁闷的是 Mozilla / FireFox 不支持 XSLT 的 Disable-Ouput-Escaping 特性,即不能把 XML 中 HTML 格式的内容按照 HTML 格式显示出来,只是将源码码输出。而 IE 5.5 即以上的浏览器对这个支持很好。

Mozilla 对这个的解释如下:


Can I do disable-output-escaping?

This is actually pretty close to the question above. And in short, no. Disabling output escaping requires us to add a parsing step to our output generation, which we don't. In most cases, there are pretty easy workarounds. The only use cases we have seen are bad XML or bad XSLT. And RSS feeds. The latter is pretty much the only issue to us, and we're sorry that we can't support it. But mixing parsing with XSLT is brittle and we rather not support d-o-e than either crash or be even slower.

也可以将 XML+XSL -> HTML 这个过程放到服务器进行,比如 Apache 就有一个个模块 mod_xslt 可以实现该功能,但这样服务器的负担就比较重,甚至超过了现在所用的直接生成 HTML 的方式。

网友留言:

我来留言