ITeye博客

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

juggler · 2007-01-30 10:51 · Markdown

xml 代码

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。