使用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. idea設(shè)置提示不區(qū)分大小寫的方法2. Java PreparedStatement用法詳解3. IntelliJ IDEA導(dǎo)出項(xiàng)目的方法4. 使用AJAX(包含正則表達(dá)式)驗(yàn)證用戶登錄的步驟5. IDEA 2020.1.2 安裝教程附破解教程詳解6. JS圖片懶加載庫(kù)VueLazyLoad詳解7. django queryset相加和篩選教程8. Spring如何集成ibatis項(xiàng)目并實(shí)現(xiàn)dao層基類封裝9. Java利用TCP協(xié)議實(shí)現(xiàn)客戶端與服務(wù)器通信(附通信源碼)10. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算

網(wǎng)公網(wǎng)安備