站长资源网络编程

使用XSL将XML文档中的CDATA注释输出为HTML文本

整理:jimmy2025/1/10浏览2
简介示例代码 1. test.xml 复制代码 代码如下: entry with ima</div> <div class="news_infos"><div id="MyContent">示例代码 <BR>1.   test.xml <BR><U>复制代码</U> 代码如下:<BR><?xml version="1.0" encoding="gb2312"?> <BR><?xml-stylesheet href="test.xsl" type="text/xsl"?> <BR><entry> <BR> <title>entry with images</title> <BR> <date>August 09, 2003</date> <BR> <author>Kevin</author> <BR> <idnum>000033</idnum> <BR> <permalink>http://alazanto.org/xml/archives/000033.xml</permalink> <BR> <body xmlns:html="http://www.w3.org/1999/xhtml"><![CDATA[<p><img <BR>  class="archive" align="right" src="/UploadFiles/2021-04-02/sample.jpg">  alt="photograph of a flower, just for show"/>Mauris felis elit, varius <BR>  quis, pulvinar vel, sodales vehicula, mi. Nunc elementum pharetra elit. <BR>  </p>]]> <BR> </body> <BR> <more xmlns:html="http://www.w3.org/1999/xhtml"><![CDATA[]]></more> <BR> <comment-link>http://alazanto.org/xml/archives/000033_comments.xml</comment-link> <BR> <comment-count>6</comment-count> <BR></entry> <BR><BR>2.  test.xsl <BR><U>复制代码</U> 代码如下:<BR><?xml version="1.0"?>  <BR><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><BR><xsl:template match="/entry">  <BR><html>  <BR><head>  <BR></head>  <BR><body>  <BR><xsl:value-of select="title" />  <BR><xsl:value-of select="body" disable-output-escaping="yes"/>  <br><br></body>  <BR></html>  <BR></xsl:template>  <BR></xsl:stylesheet> <BR><br><br>关键之外在于使用的命名空间xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 和输出时加上disable-output-escaping="yes" <BR></div> </div> </div> <div class="share"> </div> <div class="nextinfo"> <p>上一篇:<a href="http://m.wwsws.com/show/1/164908.html" title="RSS的语言编码大全">RSS的语言编码大全</a></p> <p>下一篇:<a href="http://m.wwsws.com/show/1/164910.html" title="XML指南——XML 确认">XML指南——XML 确认</a></p> </div> <div class="otherlink"> <h2>最新资源</h2> <ul> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623322.html" one-link-mark="yes" title="群星《奔赴!万人现场 第2期》[FLAC/分轨][518.87MB]"><span>群星《奔赴!万人现场 第2期》[FLAC/分轨][518.8</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623321.html" one-link-mark="yes" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[320K/MP3][43.91MB]"><span>群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[32</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623320.html" one-link-mark="yes" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[FLAC/分轨][140.49MB]"><span>群星《奇妙浪一夏 (上海迪士尼度假区音乐)》[FL</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623319.html" one-link-mark="yes" title="【古典音乐】詹姆斯·高威《季节》1993[WAV+CUE]"><span>【古典音乐】詹姆斯·高威《季节》1993[WAV+CUE]</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623318.html" one-link-mark="yes" title="贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]"><span>贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623317.html" one-link-mark="yes" title="小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]"><span>小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623316.html" one-link-mark="yes" title="群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]"><span>群星《欢迎来到我身边 电影原声专辑》[320K/MP3</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623315.html" one-link-mark="yes" title="群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]"><span>群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623314.html" one-link-mark="yes" title="雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]"><span>雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓</span></a> </li> <li> <i class="iconfont icon-point"></i> <a class="text-sm" href="/show/1/623313.html" one-link-mark="yes" title="群星《2024好听新歌42》AI调整音效【WAV分轨】"><span>群星《2024好听新歌42》AI调整音效【WAV分轨】</span></a> </li> </ul> </div> </div> <div class="sidebar"> </div> </article> <footer> <p>友情链接:<a href="http://www.imxmx.com/" title="杰晶网络" target="_blank">杰晶网络</a> <a href="http://www.ddrfans.com/" title="DDR爱好者之家" target="_blank">DDR爱好者之家</a> <a href="http://www.nqxw.com/" title="南强小屋" target="_blank">南强小屋</a> <a href="http://www.paidiu.com/" title="黑松山资源网" target="_blank">黑松山资源网</a> <a href="http://www.dyhadc.com/" title="白云城资源网" target="_blank">白云城资源网</a> <a href="/sitemap.xml">SiteMap</a></p> <p>Design by <a href="http://m.wwsws.com">伏龙阁资源网</a> <a href="/">http://m.wwsws.com</a></p> </footer> <script src="/images/nav.js"></script> <script type="text/javascript"> jQuery.noConflict(); jQuery(function() { var elm = jQuery('#left_flow2'); var startPos = jQuery(elm).offset().top; jQuery.event.add(window, "scroll", function() { var p = jQuery(window).scrollTop(); jQuery(elm).css('position', ((p) > startPos) ? 'fixed' : ''); jQuery(elm).css('top', ((p) > startPos) ? '0' : ''); }); }); </script> </body> </html>