使用XSL將XML文檔中的CDATA注釋輸出為HTML文本
更新時間:2006年09月06日 00:00:00 作者:
示例代碼
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>
關(guān)鍵之外在于使用的命名空間xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 和輸出時加上disable-output-escaping="yes"
1. test.xml
復(fù)制代碼 代碼如下:
<?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
復(fù)制代碼 代碼如下:
<?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>
關(guān)鍵之外在于使用的命名空間xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 和輸出時加上disable-output-escaping="yes"
相關(guān)文章
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-內(nèi)容目錄
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-內(nèi)容目錄...2007-02-02
xpath簡介_動力節(jié)點Java學(xué)院整理
xpath就是選擇XML文件中節(jié)點的方法。下面通過本文給大家分享xpath的相關(guān)知識,感興趣的朋友一起學(xué)習吧2017-08-08
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-簡介
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-簡介...2007-02-02
使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁的方法
使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁的方法...2007-05-05
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-操作檢查列表
氣象 XML 數(shù)據(jù)源應(yīng)用程序開發(fā)指南-操作檢查列表...2007-02-02

