使用XSL將XML文檔中的CDATA注釋輸出為HTML文本
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>
關(guān)鍵之外在于使用的命名空間xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 和輸出時(shí)加上disable-output-escaping="yes"
相關(guān)文章:
1. Android實(shí)現(xiàn)圖片自動(dòng)切換功能(實(shí)例代碼詳解)2. Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考3. JavaScript Tab菜單實(shí)現(xiàn)過程解析4. jsp+mysql實(shí)現(xiàn)網(wǎng)頁的分頁查詢5. ASP中實(shí)現(xiàn)字符部位類似.NET里String對(duì)象的PadLeft和PadRight函數(shù)6. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁7. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容8. python opencv 實(shí)現(xiàn)讀取、顯示、寫入圖像的方法9. 使用AJAX(包含正則表達(dá)式)驗(yàn)證用戶登錄的步驟10. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼
