XML中的组元素

Ano*_*non 3 xml xslt xpath

是否可以使用XSLT对XML文件中的项目进行分组?

输入文件:

<start>

<A>
---data---
</A>

<B>
---data---
</B>

<C>
---data---
</C>

<A>
---data---
</A>

<B>
---data---
</B>

</start>
Run Code Online (Sandbox Code Playgroud)

输出应该是:

<start>

<A>
---data---
</A>

<A>
---data---
</A>

<B>
---data---
</B>

<B>
---data---
</B>

<C>
---data---
</C>

</start>
Run Code Online (Sandbox Code Playgroud)

我如何使用XSL做到这一点?或者有更好的方法吗?

谢谢.

Kir*_*huk 6

样本输入:

<start>
    <A>1</A>
    <B>2</B>
    <C>3</C>
    <A>4</A>
    <B>5</B>
</start>
Run Code Online (Sandbox Code Playgroud)

XSLT:

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

    <xsl:template match="start">
        <xsl:copy>
            <xsl:for-each select="*">
                <xsl:sort select="name()"/>

                <xsl:copy-of select="."/>

            </xsl:for-each>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

输出:

<start>
  <A>1</A>
  <A>4</A>
  <B>2</B>
  <B>5</B>
  <C>3</C>
</start>
Run Code Online (Sandbox Code Playgroud)