Transformiix不支持disable-output-escaping的解决方法[转]

xml 代码
  1. Transformiix不支持disable-output-escaping的解决方法   
  2.   
  3. 最近写了一个多浏览器兼容的XSLT程序,主要问题集中在disable-output-escaping的支持上,发表一下看法,大家一起讨论。   
  4.   
  5. 我接触到的内嵌在浏览器中的XSLT Processor主要是两种:MSIE的MSXML;包括Netscape、Mozilla、Firefox等浏览器用的都是Mozilla的Transformiix。   
  6. 在http://www.w3.org/TR/xslt对XSLT的标准中,   
  7. http://www.w3.org/TR/xslt#output提到:“An XSLT processor may output the result tree as a sequence of   
  8. bytes, although it is not required to be able to do so[17   
  9. Conformance]“   
  10. http://www.w3.org/TR/xslt#disable-output-escaping:“An XSLT processor is not required to support disabling   
  11. output escaping.“   
  12. 很不幸,Transformiix不支持disable-output-escaping   
  13.   
  14. 由于在我的XML文件中,需要在浏览器上正常显示CDATA中的HTML代码,这在MSIE中,调用disable-output-escaping当然没有问题,但是既然要多浏览器兼容,就不得不考虑在Transformiix中的情况,其实这完全可以通过javascript解决,国外网站上已经有了一些解决方案,结合我的实际情况,下面给出实例代码:   
  15. <?xml version="1.0"?>  
  16. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
  17.   
  18.   <xsl:output method="html" encoding="GB2312" indent="yes"/>  
  19.   
  20.   <xsl:template match="/">  
  21.     <xsl:apply-templates/>  
  22.   </xsl:template>  
  23.   
  24.   <xsl:template match="mynode">  
  25.     <html>  
  26.       <head>  
  27.         <title>  
  28.         </title>  
  29.       </head>  
  30.       <body>  
  31.         <center id="content">  
  32.            <xsl:apply-templates select="text"/>  
  33.          </center>  
  34.       </body>  
  35.    </html>  
  36.   </xsl:template>  
  37.   
  38.   <xsl:template match="text">  
  39.     <xsl:value-of disable-output-escaping="yes" select="."/>  
  40.     <xsl:if test="system-property('xsl:vendor')='Transformiix'">  
  41.       <script language="JavaScript">  
  42.         var el = document.getElementById("content");   
  43.         elel.innerHTML = el.firstChild.data;   
  44.       </script>  
  45.     </xsl:if>  
  46.   </xsl:template>  
  47. </xsl:stylesheet>  
  48. 是不是很简单,呵呵   
  49.   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值