Sorting xslt中的排序不起作用
我正在尝试根据字段值对xml进行排序Sorting xslt中的排序不起作用,sorting,xslt,Sorting,Xslt,我正在尝试根据字段值对xml进行排序person\u id\u external 我使用的代码是: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /&g
person\u id\u external
我使用的代码是:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="A/B">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="C/person_id_external" order="ascending" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
有效载荷为:
<A>
<B>
<C>
<logon_user_name>10027</logon_user_name>
<person_id>1100111</person_id>
<person_id_external>10027</person_id_external>
</C>
</B>
<B>
<C>
<logon_user_name>428122</logon_user_name>
<person_id>11141</person_id>
<person_id_external>111358</person_id_external>
</C>
</B>
<B>
<C>
<logon_user_name>428122</logon_user_name>
<person_id>100441</person_id>
<person_id_external>10636</person_id_external>
</C>
</B>
</A>
10027
1100111
10027
428122
11141
111358
428122
100441
10636
结果提供输入的副本,但不排序
预期结果是:
<A>
<B>
<C>
<logon_user_name>10027</logon_user_name>
<person_id>1100111</person_id>
<person_id_external>10027</person_id_external>
</C>
</B>
<B>
<C>
<logon_user_name>428122</logon_user_name>
<person_id>11141</person_id>
<person_id_external>10636</person_id_external>
</C>
</B>
<B>
<C>
<logon_user_name>428122</logon_user_name>
<person_id>100441</person_id>
<person_id_external>111358</person_id_external>
</C>
</B>
</A>
10027
1100111
10027
428122
11141
10636
428122
100441
111358
干杯,
Vicky--根据您的编辑进行编辑--
在您的示例中,每个B
节点只有一个C
节点。因此,您必须对B
节点进行排序,以获得预期结果,并且必须从其父节点A
的上下文中进行排序:
<xsl:template match="A">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="C/person_id_external" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
请注意,默认的排序数据类型是文本(即字母顺序)。以下代码有效:
<xsl:template match="A">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="C/person_id_external" data-type="number" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
传入有效负载的类型为number
干杯,
Vikas Singh你的问题不清楚。请提供一个示例,其中包含多个要排序的项。-提示:XML区分大小写:
Person
与
不匹配。嗨,Michael,带P大写字母的个人文件名是一个打字错误。更改该选项时,结果也不会排序。关于有效负载,根CompoundEmployee将出现多次,并且只有一个person\u id\u外部字段所在的person节点。请不要在注释中发布代码-改为编辑您的问题。首次用户。不知道如何编辑帖子:(@Vicky添加数据类型只会更改节点的排序方式。你的问题是为什么节点根本没有排序。是的,排序不起作用…它在添加数据类型后起作用