XSLT/XSL递归嵌套元素
我需要在XSL中创建一个递归转换,XSLT/XSL递归嵌套元素,xslt,recursion,Xslt,Recursion,我需要在XSL中创建一个递归转换, 输入xml <root><foo1 /><foo2 /><foo3 /></root> 输出 <root> <foo1> <foo2> <foo3> </foo3> </foo2> <foo1> </root> 非常感谢您的帮助……尝试以下方法:
输入xml
<root><foo1 /><foo2 /><foo3 /></root>
输出
<root>
<foo1>
<foo2>
<foo3>
</foo3>
</foo2>
<foo1>
</root>
非常感谢您的帮助……尝试以下方法:
<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>