如何使用xsl从xml节点获取CDATA? [英] How to get CDATA from xml node using xsl ?

查看:133
本文介绍了如何使用xsl从xml节点获取CDATA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用XSL获取XML节点的 CDATA 内容。
节点当前看起来像这样:

I am trying to get the CDATA content of an XML node using XSL. The node currently looks like this:

<node id="1" text="Book Information" ><![CDATA[This is sample text]]></node>

我需要这是示例文本 。有人对此有任何想法吗?

I need the This is sample text piece. Does anyone have any idea about this?

预先感谢。

推荐答案

其他一些简单的步骤即可实现;

使用 W3cschools 编辑器进行试用。

示例XML文件:

Some other easy steps to achieve this;
Used W3cschools editor to try out.
Sample XML File :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<catalog>
    <cd>
        <disk id="title"><![CDATA[Sample xml]]></disk >
        <disk id="artist"><![CDATA[Vijay]]></disk >
    </cd>
</catalog>



XSL示例文件:


Sample XSL file :

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
<xsl:for-each select="catalog/cd">

      <tr>
       <td><xsl:value-of select="/catalog/cd/disk[@id='title']"/></td>
       <td><xsl:value-of select="/catalog/cd/disk[@id='artist']"/></td>
       </tr>
</xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>



最终结果是;



Final result is;

这篇关于如何使用xsl从xml节点获取CDATA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆