mule-user
mule-user

Reputation: 223

Grouping the message based on one field in mule data weaver

I have a requirement where I want to filter the incoming message based on the category='E'. So if the category = 'I', it should be trimmed off the message.

Sample Input

<DataSet>
    <SubDataSet>
        <DataNum>TEXU9022186</DataNum>
        <Category>E</Category>                             
    </SubDataSet>
    <SubDataSet>
        <DataNum>TEXU9022186T</DataNum>
        <Category>I</Category>                                  
    </SubDataSet>
    <SubDataSet>
        <DataNum>TEXU9022186T</DataNum>
        <Category>E</Category>
    </SubDataSet>
</DataSet>

Sample Output

<DataSet>
    <SubDataSet>
        <DataNum>TEXU9022186</DataNum>
        <Category>E</Category>                             
    </SubDataSet>
    <SubDataSet>
        <DataNum>TEXU9022186T</DataNum>
        <Category>E</Category>                                  
    </SubDataSet>
</DataSet>

Could you please how to achieve this by mule dataweaver

Upvotes: 0

Views: 107

Answers (1)

AnupamBhusari
AnupamBhusari

Reputation: 2415

Use filter in dataweave script as

%dw 1.0
%output application/xml
---
{DataSet : payload.DataSet.*SubDataSet filter ($.Category == "E")}

Hope this helps..

Upvotes: 1

Related Questions