Result of Transforming XML by XSLT in Different Browsers

Generally most of the browsers transform XMLs in 2 ways, I mean two kinds of APIs

For IE serial browsers, we got

xml.transformNode(xsl)

It's pretty easy, but the disadvantage is that the result is pure text.

Another way is supported by Mozilla, Opera, and Safari serial browsers

var processor = new XSLTProcessor();
processor.importStylesheet(xsl);
var result = processor.transformToDocument(xml);

It returns a document as result, that's better than IE. The problem for these browsers is, the transform result from XSLT is expected to be ONE element. Which means the following kind of result is incorrect.

<div>...</div><div>...</div>

Because they are 2 elements.

In this situation, Firefox handle it in the way that wrap the result with a <transformiix:result /> tag. Whild Safari will show an error message (TOO bad).

To solve the problem, wrap the result with another tag like

<div>
  <div>...</div>  <div>...</div> </div>

 Or another way

var result =processor.transformToFragment(xml, xml);

 For detail information of these APIs, go to the following link:

http://developer.mozilla.org/cn/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations

Although non-IE serial browsers returns DOM element for us, we can not take the advantage of it because of cross-browser issues. Instead, we have to serialize the element into a string, and then we can deal with it in the same way as IE.

var xmls = new XMLSerializer();
var html = xmls.serializeToString(result);

(Tested in IE6, FF2, Safari3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值