以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  Transformiix不支持disable-output-escaping的解决方法  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=18848)


--  作者:eagles003
--  发布时间:5/26/2005 11:12:00 AM

--  Transformiix不支持disable-output-escaping的解决方法
最近写了一个多浏览器兼容的XSLT程序,主要问题集中在disable-output-escaping的支持上,发表一下看法,大家一起讨论。

我接触到的内嵌在浏览器中的XSLT Processor主要是两种:MSIE的MSXML;包括Netscape、Mozilla、Firefox等浏览器用的都是Mozilla的Transformiix。
在[URL=http://www.w3.org/TR/xslt]http://www.w3.org/TR/xslt[/URL]对XSLT的标准中,
[URL=http://www.w3.org/TR/xslt#output]http://www.w3.org/TR/xslt#output[/URL]提到:“An XSLT processor may output the result tree as a sequence of
bytes, although it is not required to be able to do so[17
Conformance]“
[URL=http://www.w3.org/TR/xslt#disable-output-escaping]http://www.w3.org/TR/xslt#disable-output-escaping[/URL]:“An XSLT processor is not required to support disabling
output escaping.“
很不幸,Transformiix不支持disable-output-escaping

由于在我的XML文件中,需要在浏览器上正常显示CDATA中的HTML代码,这在MSIE中,调用disable-output-escaping当然没有问题,但是既然要多浏览器兼容,就不得不考虑在Transformiix中的情况,其实这完全可以通过javascript解决,国外网站上已经有了一些解决方案,结合我的实际情况,下面给出实例代码:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" encoding="GB2312" indent="yes"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="mynode">
    <html>
      <head>
        <title>
        </title>
      </head>
      <body>
        <center id="content">
           <xsl:apply-templates select="text"/>
         </center>
      </body>
   </html>
  </xsl:template>

  <xsl:template match="text">
    <xsl:value-of disable-output-escaping="yes" select="."/>
    <xsl:if test="system-property('xsl:vendor')='Transformiix'">
      <script language="JavaScript">
        var el = document.getElementById("content");
        el.innerHTML = el.firstChild.data;
      </script>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
是不是很简单,呵呵

[URL=http://www.forum4designers.com/archive88-2005-4-211776.html]http://www.forum4designers.com/archive88-2005-4-211776.html[/URL]
[URL=http://use.perl.org/~TorgoX/journal/24272]http://use.perl.org/~TorgoX/journal/24272[/URL]
[URL=http://www.xml.com/pub/a/2003/08/20/embedded.html]http://www.xml.com/pub/a/2003/08/20/embedded.html[/URL]


--  作者:guan1200
--  发布时间:6/1/2005 2:58:00 PM

--  
不错方法
--  作者:chenshijun
--  发布时间:6/24/2005 7:10:00 PM

--  
挺有意思的!
--  作者:观摩
--  发布时间:1/13/2006 6:55:00 PM

--  
呵呵,谢谢楼主


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms