使用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. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁(yè)2. ASP.NET MVC使用JSAjaxFileUploader插件實(shí)現(xiàn)單文件上傳3. 解決python logging遇到的坑 日志重復(fù)打印問(wèn)題4. 使用AJAX實(shí)現(xiàn)上傳文件5. Python dict的常用方法示例代碼6. Python:UserWarning:此模式具有匹配組。要實(shí)際獲得組,請(qǐng)使用str.extract7. Android Studio / IDEA kotlin 顯示 var 真實(shí)類型操作8. Spring boot基于ScheduledFuture實(shí)現(xiàn)定時(shí)任務(wù)9. Android實(shí)現(xiàn)下載進(jìn)度條效果10. PHP腳本的10個(gè)技巧(8)
