Xml 如何在XSLT转换中对结果进行排序?

Xml 如何在XSLT转换中对结果进行排序?,xml,xslt,saxon,Xml,Xslt,Saxon,在将结果写入输出流之前,是否可以在xslt转换中对结果进行排序 我的目标是1)将以下xml转换为csv,2)根据中发生的数量对人员进行排序 示例:在下面的示例中,最后一个人节点仅包含1个人。因此,我想在最终输出的所有结果之上对此人进行排序 然后,应打印所有已在节点中有2人的人员。然后是3…,然后是N source.xml: <personNodes> <personNode> <person> <id>

在将结果写入输出流之前,是否可以在
xslt
转换中对结果进行排序

我的目标是1)将以下xml转换为csv,2)根据
中发生的
数量对人员进行排序

示例:在下面的示例中,最后一个人节点仅包含1个人。因此,我想在最终输出的所有结果之上对此人进行排序

然后,应打印所有已在节点中有2人的人员。然后是3…,然后是N

source.xml:

<personNodes>
    <personNode>
        <person>
            <id>1</id>        
            <name>john</name>
        </person>
        <person>
            <id>11</id>        
            <name>doe</name>
        </person>
    </personNode>
    <personNode>
        <person>
            <id>2</id>        
            <name>jane</name>
        </person>
    </personNode>
</personNodes>
重新调整大小的结果:

#person from 1-person node
2;jane
#persons from 2-person nodes
1;john
11;doe
#persons from 3-person nodes
...
#persons from N-person nodes
这可能吗,因为我只是通过
将结果打印到输出流中?也许我必须在
映射
列表
变量中收集csv行,然后在循环结束时再次打印到输出?

这样如何

<xsl:for-each select="personNode/person">
    <xsl:sort select="../count(person)" />
    <xsl:value-of select="concat(id, ': ', name, '&#10;')"/>
</xsl:for-each>

这个怎么样

<xsl:for-each select="personNode/person">
    <xsl:sort select="../count(person)" />
    <xsl:value-of select="concat(id, ': ', name, '&#10;')"/>
</xsl:for-each>

使用
xsl:sort
当然:

<xsl:template match="personNodes">
    <xsl:for-each select="personNode">
        <xsl:sort select="count(person)"/>
        <xsl:for-each select="person">
            <xsl:value-of select="concat(id, ': ', name, '&#10;')"/>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>

使用
xsl:sort
当然:

<xsl:template match="personNodes">
    <xsl:for-each select="personNode">
        <xsl:sort select="count(person)"/>
        <xsl:for-each select="person">
            <xsl:value-of select="concat(id, ': ', name, '&#10;')"/>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>
<xsl:for-each select="sort(personNode, (), function($p) { count($p/person) })">