it编程 > 网页制作 > Xml

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

67人参与 2024-05-19 Xml

示例代码

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"

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

轻松学习XML教程

05-19

XML 取得元素的字符数据

05-19

读写xml文件的2个小函数

05-19

怎样才能用js生成xmldom对象,并且在firefox中也实现xml数据岛?

05-19

博客日志摘要暨RSS技术

05-19

XMLDOM对象方法:对象属性

05-19

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论