打印节点

时间:2016-05-27 17:29:32

标签: html xml xslt xpath

我有一个像这样的XML文件

<users>
  <user>
    <name>X</name>
    <description>
      This is a <it>description</it> of the <a href="www.google.com">user</a>.
    </description>
  </user>
  <user>
    <name>Y</name>
    <description>
      This is a <it>description</it> of another user.
    </description>
  </user>
  <user>
    <name>Z</name>
    <description>
      This is a description of the <a href="www.google.com">third</a> user.
    </description>
  </user>
</users>

我必须创建一个XSL文件,将其转换为如下所示的HTML:

<h1>Users</h1>
<h2>X</h2>
<p>This is a <it>description</it> of the <a href="www.google.com">user</a>.</p>
<h2>Y</h2>
<p>This is a <it>description</it> of another user.</p>
<h2>Z</h2>
<p>This is a description of the <a href="www.google.com">third</a> user.</p>

所以基本上我需要获取<description>标签的原始数据并将其打印成段落。但我不知道该怎么做。有什么想法吗?

到目前为止我的XSL代码:

<xsl:for-each select="users/user">
  <h2><xsl:value-of select="name" /></h2>
  <p><xsl:value-of select="description"/></p>
</xsl:for-each>

0 个答案:

没有答案