用XSL的xsl:copy-of将XML中CDATA节点内容直接输出为HTML
2007/7/25 8:59:05
阅读全文(6355) | 回复(1) | 编辑 | 精华
前些日子发“如果浏览器不支持disable-output-escaping="yes"属性?”的时候,只讲到用<xsl:copy-of>,但没有细说如何实现。论坛上依然发了不少相关的贴子,询问该如何实现。今天就贴点代码上来,希望对大家有帮助。 html.xml: <?xml version="1.0"?><?xml-stylesheet type="text/xsl" href ="html.xsl"?><root><htmlstr><![CDATA[<html><body><div>test</div></body></html>]]></htmlstr></root> 常用的方法是用disable-output-escaping="yes"来输出: <xsl:value-of select="htmlstr" disable-output-escaping="yes"/> 但相当一部分浏览器不支持disable-output-escaping属性,也是W3C所不推荐的。xsl:copy-of才是最佳的解决方案。 html.xsl: <?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="root"> <xsl:copy-of select="htmlstr/node()"/> </xsl:template></xsl:stylesheet> 输出结果:<html><body><div>test</div></body></html>
Posted by Qr on 2007/7/25 8:59:05
回复:用XSL的xsl:copy-of将XML中CDATA节点内容直接输出为HTML
2008/5/7 0:36:08
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
为什么我用 copy-of 不但 firefox 里解决不了问题, IE 也和 firfox 一样了 以下为blog主人的回复: http://bbs.xml.org.cn/dispbbs.asp?BoardID=8&id=50492
alvin(游客)
Posted by alvin(游客) on 2008/5/7 0:36:08
发表评论: |