【问题标题】:XSLT/XSL recursive nested elementsXSLT/XSL 递归嵌套元素
【发布时间】:2013-06-26 11:11:19
【问题描述】:

我需要在 XSL 中创建递归转换,
输入xml

<root><foo1 /><foo2 /><foo3 /></root>

输出

<root> 
 <foo1>
   <foo2>
     <foo3>
     </foo3>
    </foo2>
  <foo1> 
</root>

非常感谢您的帮助...

【问题讨论】:

标签: xslt recursion


【解决方案1】:

试试这样的:

  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>

    <xsl:template match="/root">
        <xsl:copy>
            <xsl:apply-templates select="*[1]" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:apply-templates select="following-sibling::*[1]" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

这将生成以下输出:

<?xml version="1.0"?>
<root>
  <foo1>
    <foo2>
      <foo3/>
    </foo2>
  </foo1>
</root>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多