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脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前
By DDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前
By DDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前
By DDD
<🎜>:死铁路 - 如何完成所有挑战
4 周前
By DDD
Atomfall指南:项目位置,任务指南和技巧
1 个月前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

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

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)