cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting a field in mapping based on another

Former Member
0 Kudos

Hi,

I have a strucutre like the following...

SOURCE

<node>
    <aa>B_test</aa>
    <bb>iu</bb>
    <cc></cc>
</node>
<node>
    <aa>A_test2</aa>
    <bb>NO</bb>
    <cc>resource</cc>
</node>
<node>
    <aa>C_test3</aa>
    <bb>No</bb>
    <cc>resource</cc>
</node>

after mapping, my message is like this......

TARGET

<node>
    <aa>A_test2</aa>
    <bb>NO</bb>
  *bold*   <cc>NIMOY</cc>
</node>
<node>
    <aa>B_test</aa>
    <bb>iu</bb>
    *bold* <cc>resource</cc>
</node>
<node>
    <aa>C_test3</aa>
    <bb>No</bb>
    <cc>resource</cc>
</node>

but it should be like this


<node>
    <aa>A_test2</aa>
    <bb>NO</bb>
*bold*     <cc>resource</cc>
</node>
<node>
    <aa>B_test</aa>
    <bb>iu</bb>
*bold*     <cc>NIMOY</cc>
</node>
<node>
    <aa>C_test3</aa>
    <bb>No</bb>
    <cc>resource</cc>
</node>

I have to check <bb> for the value "iu". This is no problem. If it contains "iu" then map the constant NIMOY to <cc>. Then sort the <node> element in ascending order based on <aa>. The problem is that I cannot get <cc> to sort. It just stays in the same order. I've been trying to use combinations of SortByKey and FormatByExample. The fields <aa> and <bb> will sort but not <cc>.Any ideas??

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos
Former Member
0 Kudos

Raj,

That worked for me. Thanks very much for your very detailed answer. The screenshots were a great help and much appreciated

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Damien,

this is only possible with complicated UDF.

You have to write all Elements to the globalContainerElement. Also you need a collection for the sort.

The sort-function of graphical mapping does only sort the node where you assinged the function. Not the child elements.

Better is JAVA, ABAP or XSLT.

Regards Mario

Edited by: Mario Müller on Feb 15, 2008 1:55 PM

Former Member
0 Kudos

Hi,

Generally records get sorted depending on the mandatory and unique filelds in the structure.

Your scenario is not working, then check if that node exists using "exists" function and then only proceed with the sorting

Refer below discussion,

Thanks

Swarup

VijayKonam
Active Contributor
0 Kudos

The sort functionality available at node only works at that particular element level. You can not sort a NODE based on one element in that node and other elements follow with it.

You have to write a AUDF for this, by caching the entire Queues of the elements involved and sort them and create the output node structure.

VJ