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

XML
数据库生成xml的简单方法
XML教程:通过一个例子来学习XML的语法
XML教程:XML有哪些用途?
XML教程:什么是XML及XML和HTML的区别
初学XML的基础知识(认识XML的作用)
学习XML关于图像超链接的制作
Microsoft的XMLHTTP对象介绍
了解WEB页面工具语言XML(六)展望
了解WEB页面工具语言XML(五)好处
用XML将机器内码转换为人们容易理解的信息
将XML数据转换成HTM
(javascript+asp)XML、XSL转换输出HTML
在XML模式中扩展枚举列表
XML入门教程:XML名称空间
XML入门教程:属性声明
XML入门教程:实体
XML入门教程:元素声明
XML入门教程:文档类型声明
xml入门教程:XML是什么
WAP教程(11):WAP论坛和开放移动联盟与论坛

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


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