webdn
 
  首页     免费截图     VIP会员区     广告Banner     技术文档     网站模板  
网站截图,网站每日新 !
虚拟主机 域名注册

首页 >> WebDN 技术文档 >> 网站制作 >> XML技术大全 >> 使用XSL将XML文档中的CDATA注释输出为HTML文本

 

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

【摘 要】要利用DOM 来存取XML 文件,你必须将XML 文件连结到HTML 网页上。

示例代码

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[]]></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"


  | 
点击这里给我发消息 | 关于WebDN  |  站点地图  |  联系我们  |  WebDN 会员  |  支付方式  |  友情链接  |  隐私政策
© 2004-2008 WebDN.com 版权所有. 沪ICP备05040479号