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

XML
WML学习之七 CGI编程
WAP建站WML语言语法基础教程
WML语法大全与相关介绍
非常不错的WAP常见问题问答大全(二)
WML语言的基本情况
WML开发教程之 WAP网站服务器配置方法
WMLScript的语法基础
收集的WML Script标准函数库
WML教程之文本框控件Input
WMLScript脚本程序设计
WML的简单例子及编辑、测试方法
初试WAP之wml+ASP查询
无线标记语言(WML)基础之WMLScript 基础
xml文件的结构解读
关于XSL - XSL教程
选择模式 - XSL教程 - 2
XPath入门 - XSL教程 - 3
匹配模式 - XSL教程 - 4
测试模式 - XSL教程 - 5
三十分钟掌握STL-教程

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


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