将CDATA中的HTML代码输出
糊糊 2007-07-20 01:07:33 我按照http://hi.baidu.com/lanxmail/blog/item/a4e8bc8f20e931fb513d9296.html所说的测试过,IE可行,Opera不行
我将他的测试代码改了改,加入了xsl:copy和xsl:copy-of,IE表现还行
xml文件
------------------------------
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='a.xsl'?>
<test>
<html1>
<b>
<![CDATA[
<hr/><div><font color="red">111</font></div>
<div style="border:1px solid blue;width:100px">hhhh</div>
<div>qqq</div>
]]>
</b>
</html1>
<html2>
<![ CDATA [
<hr/><div><font color="red">222</font></div>
<div style="border:1px solid blue;width:100px">hhhh</div>
<div>qqq</div>
]]>
</html2>
</test>
=====================
xsl文件
--------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="test">
<html>
<title>test cdata</title>
<body>
<xsl:apply-templates/>
</body></html>
</xsl:template>
<xsl:template match="test">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="html1">
方法一:
<div style="border:1px solid #ccc">
使用了node(): <xsl:copy-of select="node()"/>
<br/>
使用了text(): <xsl:copy-of select="text()"/>
<br/>
使用了./node(): <xsl:copy-of select="./node()"/>
<br/>
使用了./text(): <xsl:copy-of select="./text()"/>
<br/>
</div>
</xsl:template>
<xsl:template match="html2">
方法2:
<div style="border:1px solid #ccc">
<xsl:value-of select="node()" disable-output-escaping="yes"/>
</div>
</xsl:template>
</xsl:stylesheet>
==========================
名字为a.xml,a.xsl,在IE中测试,只有第二种方法行。xsl:copy-of 好像不起作用,xsl:copy也不起作用,错误在哪里?
cdata中的html通过xsl:copy和xsl:copy-of输出html都被编码了
===============
你使用GreenBrowser或者Maxthon查看XML文件(带XSL)的,运行页面分析插件,点源码就可以看到xsl格式化xml后生成的html