我熟悉XSLT的基础知识,但我遇到了一个奇怪的情况,我似乎无法弄清楚。我很抱歉这么久,但我会很感激你能提供的任何帮助。按多个元素排序
我想根据排序的品牌/价值/ @名称和文件/价值/ @名称的串联,从而易排序Level_5
XML unsorted:
<Root att="x">
<Level_1 Name="NEW Level">
<Level_2>
<Level_3 Name="nameLvl_3">
<Level_4>
<Level_5 Name="aa">
<Brand>
<Value Name="Text" Value="1" />
</Brand>
<Docs>
<Value Name="Pro" Value="2" />
<Value Name="Numeric" Value="0.05" />
</Docs>
</Level_5>
<Level_5 Name="aa">
<Text>
<Val Id="1"/>
</Text>
</Level_5>
<Level_5 Name="aa">
<Brand>
<Value Name="Text" Value="2" />
<Value Name="Number" Value="1" />
<Value Name="Long" Value="3" />
</Brand>
</Level_5>
</Level_4>
</Level_3>
</Level_2>
</Level_1>
</Root>
你做拼接后,您应该排序Level_5节点, “” LongNumberText,TextNumericPro 和预期输出是:
<Root att="x">
<level_1 Name="NEW Level">
<level_2>
<Level_3 Name="nameLvl_3">
<Level_4>
<Level_5 Name="aa">
<Text>
<Val Id="1"/>
</Text>
</Level_5>
<Level_5 Name="aa">
<Brand>
<Value Name="Long" Value="3" />
<Value Name="Number" Value="1" />
<Value Name="Text" Value="2" />
</Brand>
</Level_5>
<Level_5 Name="aa">
<Brand>
<Value Name="Text" Value="1" />
</Brand>
<Docs>
<Value Name="Numeric" Value="0.05" />
<Value Name="Pro" Value="2" />
</Docs>
</Level_5>
</Level_4>
</Level_3>
</Level_2>
</Level_1>
</Root>
我只能排序的/品牌/价值/ @名称的第一个元素,但我没有任何想法如何拼接的休息品牌和文档内的属性,这是代码即时NG:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Level_3/Level_4/Level_5/Brand|Docs">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="@Name" data-type="text"/>
<xsl:sort select="@Value" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!-- -->
<xsl:template match="Level_2/Level_3/Level_4">
<xsl:copy>
<xsl:apply-templates select="Level_5">
<xsl:sort select="Brand|Docs/Value/@Name" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
但我只是排序再见品牌的内部或文档请任何帮助的第一个元素
我已经做了两步,但我被限制在一步做到这一点 – user1789798