[英]Need to perform a double nested sort on xslt 1.0
Worked on the solution Sandy gave me, it worked fine, but then I realized the code is more nested.使用桑迪给我的解决方案,它工作得很好,但后来我意识到代码更加嵌套。 Been trying to solve it but no luck.一直在尝试解决它,但没有运气。
This part is working fine on sorting the WorkingQueue.这部分在对工作队列进行排序时工作正常。
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="WorkingQueues">
<xsl:copy>
<xsl:for-each select="WorkingQueue">
<xsl:sort select="@queueId" order="ascending" data-type="number"/>
<xsl:copy>
<xsl:copy-of select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
Adding this part (+ removing the WorkingQueue) made it sort for the ValidationAction Somehow I need to shift this part into the first for-each loop.添加这部分(+ 删除工作队列)使其排序为 ValidationAction 不知何故,我需要将此部分转移到第一个 for-each 循环中。 All my efforts returned a mess.我所有的努力都一团糟。
<xsl:template match="Actions">
<xsl:copy>
<xsl:for-each select="ValidationAction">
<xsl:sort select="@actionLabel" order="ascending"/>
<xsl:copy>
<xsl:copy-of select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
This is the code which needs to be sorted on WorkingQueue@queueId and ValidationAction@actionLabel这是需要在 WorkingQueue@queueId 和 ValidationAction@actionLabel 上排序的代码
<Export>
<WorkingTemplates>
<WorkingTemplate label="MM_DR">
<WorkingQueues>
<WorkingQueue queueId="132" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="BrkNotOk" enabled="true"/>
<ValidationAction actionLabel="AddComment" enabled="true"/>
</Actions>
</WorkingQueue>
<WorkingQueue queueId="49" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="BrkNotOk" enabled="true"/>
<ValidationAction actionLabel="AddComment" enabled="true"/>
</Actions>
</WorkingQueue>
</WorkingQueues>
</WorkingTemplate>
<WorkingTemplate label="FX_MA">
<WorkingQueues>
<WorkingQueue queueId="123" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="BrkNotOk" enabled="true"/>
<ValidationAction actionLabel="AddComment" enabled="true"/>
</Actions>
</WorkingQueue>
<WorkingQueue queueId="60" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="Accept" enabled="true"/>
</Actions>
</WorkingQueue>
</WorkingQueues>
</WorkingTemplate>
</WorkingTemplates>
</Export>
Expected result:预期结果:
<Export>
<WorkingTemplates>
<WorkingTemplate label="MM_DR">
<WorkingQueues>
<WorkingQueue queueId="49" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="AddComment" enabled="true"/>
<ValidationAction actionLabel="BrkNotOk" enabled="true"/>
</Actions>
</WorkingQueue>
<WorkingQueue queueId="132" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="AddComment" enabled="true"/>
<ValidationAction actionLabel="BrkNotOk" enabled="true"/>
</Actions>
</WorkingQueue>
</WorkingQueues>
</WorkingTemplate>
<WorkingTemplate label="FX_MA">
<WorkingQueues>
<WorkingQueue queueId="60" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="Accept" enabled="true"/>
</Actions>
</WorkingQueue>
<WorkingQueue queueId="123" right="READ_WRITE">
<Actions>
<ValidationAction actionLabel="AddComment" enabled="true"/>
<ValidationAction actionLabel="BrkNotOk" enabled="true"/>
</Actions>
</WorkingQueue>
</WorkingQueues>
</WorkingTemplate>
</WorkingTemplates>
</Export>
I am guessing (:) you want to do:我猜 (:) 你想做:
XSLT 1.0 XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="WorkingQueues">
<xsl:copy>
<xsl:apply-templates select="WorkingQueue">
<xsl:sort select="@queueId" data-type="number" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="Actions">
<xsl:copy>
<xsl:apply-templates select="ValidationAction">
<xsl:sort select="@actionLabel" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.