用户登录
用户注册

分享至

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

  • 作者: 馹馫馫馫
  • 来源: 51数据库
  • 2021-07-05
示例代码

1. test.xml

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet 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.51sjk.com/Upload/Articles/1/0/260/260043_20210701002858749.jpg"><![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"

软件
前端设计
程序设计
Java相关