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

XML
一个以Javascript+xml的树型列表
用ajax技术制作在线歌词搜索功能
网络编程:如何生成XML数据
如何让WebServer返回指定XML内容
网页编程必看:XML文法分析
编程:如何生成XML数据
用PHP与XML联手进行网站编程
Javascript+XML实现分页的实例
XML技巧五则
使用xmlhttp为网站增加域名查询功能
详解XML-RPC和JAX-RPC
XML在.net平台下的自定义控件的应用(1)
XML在.net平台下的自定义控件的应用(2)
基础知识认识XML:下一代网络的基石
Web2.0岁月:使用AJAX技术的十大理由
了解 XML实现通用的数据访问
AJAX基础教程及初步使用
Web设计中如何使用XML数据
AJAX应用之草稿自动保存
XML 中的常见问题(一)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 53 ::
收藏到网摘: 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"