如何根据 wso2esb 中的数据对 xml 元素进行排序 [英] How to sort the xml element based on data in wso2esb

查看:17
本文介绍了如何根据 wso2esb 中的数据对 xml 元素进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wso2esb.我希望使用 wso2esb 转换数据我已经完成的问题是响应我以降序方式获取数据时我将如何以升序方式排列.

I am using wso2esb. I wish to transform the data using wso2esb i have done the issue is while response i am getting data in descending manner how would i arrange in to ascending way .

<response>
    <customer-details>
        <cusfirstname>Empire Burlesque</cusfirstname>
        <delarname>Bob Dylan</delarname>
        <cusno>254</cusno>
    </customer-details>
    <customer>
        <cusId>6</cusId>
        <customername>Bonnie Tyler</customername>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </customer>
    <customer>
        <cusId>8</cusId>
        <customername>Dolly Parton</customername>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </customer>
    <customer>
        <cusId>3</cusId>
        <customername>Gary Moore</customername>
        <country>UK</country>
        <company>Virgin records</company>
        <price>10.20</price>
        <year>1990</year>
    </customer>
    <customer>
        <cusId>5</cusId>
        <customername>Eros Ramazzotti</customername>
        <country>EU</country>
        <company>BMG</company>
        <price>9.90</price>
        <year>1997</year>
    </customer>
    <customer>
        <cusId>7</cusId>
        <customername>Bee Gees</customername>
        <country>UK</country>
        <company>Polydor</company>
        <price>10.90</price>
        <year>1998</year>
    </customer>
    <customer>
        <cusId>1</cusId>
        <customername>Dr.Hook</customername>
        <country>UK</country>
        <company>CBS</company>
        <price>8.10</price>
        <year>1973</year>
    </customer>
    <customer>
        <cusId>2</cusId>
        <customername>Rod Stewart</customername>
        <country>UK</country>
        <company>Pickwick</company>
        <price>8.50</price>
        <year>1990</year>
    </customer>
    <customer>
        <cusId>4</cusId>
        <customername>Andrea Bocelli</customername>
        <country>EU</country>
        <company>Polydor</company>
        <price>10.80</price>
        <year>1996</year>
    </customer>
    <customer>
        <cusId>12</cusId>
        <customername>Percy Sledge</customername>
        <country>USA</country>
        <company>Atlantic</company>
        <price>8.70</price>
        <year>1987</year>
    </customer>
    <customer>
        <cusId>9</cusId>
        <customername>Savage Rose</customername>
        <country>EU</country>
        <company>Mega</company>
        <price>10.90</price>
        <year>1995</year>
    </customer>
    <customer>
        <cusId>11</cusId>
        <customername>Many</customername>
        <country>USA</country>
        <company>Grammy</company>
        <price>10.20</price>
        <year>1999</year>
    </customer>
    <customer>
        <cusId>10</cusId>
        <customername>Kenny Rogers</customername>
        <country>UK</country>
        <company>Mucik Master</company>
        <price>8.70</price>
        <year>1995</year>
    </customer>
</response>

我希望根据 cusId 以升序排列 customer 标记数据,那么我将如何安排这个我尝试使用 xquery 但我找不到任何功能关于元素排序,cusId 应该出现在 1,2,3,...

I wish to arrange the customer tag data in ascending order based on cusId so how would i arrange this I tried with xquery but i couldn't find the any function regarding element sorting , cusId should be appear in 1,2,3,...

我将如何实现这一点,我知道 xpath 中没有此功能.

How would i achieve this i know there is no function in xpath for this.

提前致谢.

推荐答案

在 XSLT 中使用 <xsl:apply-templates> 时可以使用 <xsl:sort>每个客户的code>.此样式表对客户进行排序:

In XSLT you can use <xsl:sort> when using <xsl:apply-templates> for each customer. This stylesheet orders the customers:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="response">
        <xsl:copy>
            <xsl:apply-templates select="customer-details"/>
            <xsl:apply-templates select="customer">
                <xsl:sort select="cusId"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

这篇关于如何根据 wso2esb 中的数据对 xml 元素进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆