XSL將XML中的CDATA註解輸出為HTML文字的程式碼實例
html
xml
xsl
要利用DOM 來存取XML 文件,你必須將XML 文件連結到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>
登入後複製
登入後複製
關鍵之外在於使用的命名空間xmlns:xsl="www.w3.org/1999/XSL/Transform" 和輸出時加上disable-output-escaping="yes"
範例程式碼
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>
登入後複製
登入後複製
關鍵之外在於使用的命名空間xmlns:xsl="http://www.w3.org/1999/XSL /Transform" 和輸出時加上disable-output-escaping="yes"
以上是XSL將XML中的CDATA註解輸出為HTML文字的程式碼實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
3 週前
By DDD
Windows 11 KB5054979中的新功能以及如何解決更新問題
2 週前
By DDD
威爾R.E.P.O.有交叉遊戲嗎?
1 個月前
By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)
