使用XSL将XML文档中的CDATA注释输出为HTML文本

发表于:2007-06-30来源:作者:点击数: 标签:
示例代码 1. test.xml ?xml version="1.0" encoding="gb2312"? ?xml-stylesheet href="test.xsl" type="text/xsl"? entry titleentry with images/title dateAugust 09, 2003/date authorKevin/author idnum000033/idnum permalinkhttp://alazanto.org/xml/a

示例代码

1.   test.xml

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<entry>
 <title>entry with images</title>
 <date>August 09, 2003</date>
 <author>Kevin</author>
 <idnum>000033</idnum>
 <permalink>http://alazanto.org/xml/archives/000033.xml</permalink>
 <body xmlns:html="
  class="archive" align="right" src=""
  alt="photograph of a flower, just for show"/>Mauris felis elit, varius
  quis, pulvinar vel, sodales vehicula, mi. Nunc elementum pharetra elit.
  </p>]]>
 </body>
 <more xmlns:html=">
 <comment-link>http://alazanto.org/xml/archives/000033_comments.xml</comment-link>
 <comment-count>6</comment-count>
</entry>

2.  test.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">

<xsl:template match="/entry">
<html>
<head>
</head>
<body>
<xsl:value-of select="title" />
<xsl:value-of select="body" disable-output-escaping="yes"/>

</body>
</html>
</xsl:template>
</xsl:stylesheet>


关键之外在于使用的命名空间xmlns:xsl="" 和输出时加上disable-output-escaping="yes"

原文转自:http://www.ltesting.net