在论坛中经常会碰到此类问题,回答的次数也记不清了.
XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<![CDATA[
<font color=red><b>ssm1226</b></font>
]]>
</root>
使用XSL对其进行转换时,标准与草案中的处理是不同的.
标准中:
查看下<xsl:value-of>标记说明:
<xsl:value-of
select = expression
disable-output-escaping = "yes" | "no"
</xsl:value-of>
其中:disable-output-escaping:
Default is "no". If the value is "yes", a text node generated by instantiating the <xsl:value-of> element will be output without any escaping. For example, the following generates the single character "<"
.
<xsl:value-of disable-output-escaping="yes" select="<"/>
针对以上XML文件,XSL文件可以这样:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:value-of select="/root" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
草案中的<xsl:eval>计算脚本表达式,输出一个文本字符串
xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:eval no-entities="true">this.text</xsl:eval>
</xsl:template>
</xsl:stylesheet>
输出HTML代码:
<font color=red><b>ssm1226</b></font>