使用XSL將XML文檔中的CDATA注釋輸出為HTML文本
更新時(shí)間: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" 和輸出時(shí)加上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" 和輸出時(shí)加上disable-output-escaping="yes"
相關(guān)文章
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-內(nèi)容目錄
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-內(nèi)容目錄...2007-02-02
xpath簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
xpath就是選擇XML文件中節(jié)點(diǎn)的方法。下面通過(guò)本文給大家分享xpath的相關(guān)知識(shí),感興趣的朋友一起學(xué)習(xí)吧2017-08-08
UTF8轉(zhuǎn)成GB2312亂碼問(wèn)題解決方案
審核完的信息要生成XML類型的文件,并且XML要采用GB2312編碼,因?yàn)椴杉男侣劸W(wǎng)站,有很多網(wǎng)站采用的是UTF8編碼,這樣在轉(zhuǎn)化的過(guò)程中又出現(xiàn)亂碼2013-04-04
用Asp與XML實(shí)現(xiàn)交互的一個(gè)實(shí)例源碼
用Asp與XML實(shí)現(xiàn)交互的一個(gè)實(shí)例源碼...2007-11-11
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-簡(jiǎn)介
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-簡(jiǎn)介...2007-02-02
使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法
使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法...2007-05-05
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-操作檢查列表
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-操作檢查列表...2007-02-02

