首页 > 解决方案 > 使用 xslt 从 xml 获取 HTML 列表中的值

问题描述

下面有两个 XML 列表 ( sub1, sub2)。我们可以编写一个 XSLT 来将它们转换为带有ol标签的 HTML 吗?

<sub1>
  <number>(1)</number>
  <para-text align="left" indent="0">XYZ</para-text>
  <sub2>
    <number>(a)</number>
    <para-text align="left" indent="0">ABC</para-text>
  </sub2>
  <sub2>
    <number>(b)</number>
    <para-text align="left" indent="0">DEF</para-text>
  </sub2>
  <sub2>
    <number>(c)</number>
    <para-text align="left" indent="0">GHI</para-text>
  </sub2>
</sub1>

我使用了以下模板(当前节点的值),但未能成功。

<xsl:template match="/sub1">
  <ol>
    <li>
      <xsl:for-each select="para-text">
        <xsl:value-of select="current()" /> </xsl:for-each>
    </li>
  </ol>
</xsl:template>

我正在寻找的 HTML 结构就像

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
<ol>
<li></li>
<li></li>
</ol>
</body>
</html>

标签: htmlxmlxslt-2.0

解决方案


推荐阅读