当前位置: 首页 > 图文教程 > XML家族 > XML > 使用XSL将XML文档中的CDATA注释输出为HTML文本

XML
XML 中的常见问题(二)
XML轻松学习手册(1)XML快速入门
XML入门的常见问题(三)
XML入门的常见问题(四)
XML轻松学习手册(2)XML概念
轻松学习手册(3)XML的术语
XML轻松学习手册(4)XML语法
XML轻松学习手册(5)XML实例解析
XML卷之实战锦囊(1):动态排序
XML卷之实战锦囊(2):动态查询
XML卷之实战锦囊(3):动态分页
XML卷之实战锦囊(4):选单连动
XML卷之实战锦囊(5):结构树图
对XML数据使用XMLConvert
XSL基础教程第一章
XSL基础教程第二章
XSL基础教程第三章
XSL基础教程第四章
XSL基础教程第五章
具体实现 XML 的三种方式

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 55 ::
收藏到网摘: n/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="http://www.w3.org/1999/xhtml"><![CDATA[<p><img
  class="archive" align="right" src="http://alazanto.org/images/sample.jpg"
  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="http://www.w3.org/1999/xhtml"><![CDATA[]]></more>
 <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="http://www.w3.org/1999/XSL/Transform" 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="http://www.w3.org/1999/XSL/Transform" 和输出时加上disable-output-escaping="yes"