简体   繁体   English

需要执行嵌套数字排序 (xslt 1.0)

[英]Need to perform a nested numeric sort (xslt 1.0)

Below XML needs to be sorted on queueId per WorkingTemplate using XSLT 1.0 XML 下面需要使用 XSLT 1.0 对每个 WorkingTemplate 的 queueId 进行排序

Reason for asking here: All examples seen till now are not having these kind of structures.在这里问的原因:到目前为止看到的所有示例都没有这种结构。 Therefore I can't attach any working xslt for this.因此我不能为此附加任何有效的 xslt 。 Please help.请帮忙。

<Export>
    <WorkingTemplates>
        <WorkingTemplate label="MM_DR">
            <WorkingQueues>
                <WorkingQueue queueId="132" right="READ_WRITE"/>
                <WorkingQueue queueId="49" right="READ_WRITE"/>
                <WorkingQueue queueId="197" right="NO_ACCESS"/>
            </WorkingQueues>
        </WorkingTemplate>
        <WorkingTemplate label="FX_MA">
            <WorkingQueues>
                <WorkingQueue queueId="123" right="READ_WRITE"/>
                <WorkingQueue queueId="60" right="READ_WRITE"/>
                <WorkingQueue queueId="182" right="NO_ACCESS"/>
            </WorkingQueues>
        </WorkingTemplate>
    </WorkingTemplates>
</Export> ```


[![Situation before sort][1]][1]


[![Situation after sort][2]][2]


  [1]: https://i.stack.imgur.com/5ojwu.png
  [2]: https://i.stack.imgur.com/fmyKf.png

You can try this use for-each你可以试试这个用法for-each

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="1.0">
    <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <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="@*"/>
                </xsl:copy>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM