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

王朝html/css/js·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

示例代码

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="]></more]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"

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航