2013-06-28 71 views
1

我需要创建XSL递归改造,
输入XMLXSLT/XSL Recusive嵌套元素

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

输出

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

非常感谢您的帮助......

+0

http://stackoverflow.com/questions/17370562/transformation-in-xslt-with-recursive-nested-templates – user902870

回答

3

试试这样的:

<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>