cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping question

Former Member
0 Kudos

All,

We have a source xml from a legacy system in the following format

<sourcemessage>

<data>AGRO</data>

<data>A3334</data>

<data>product 1</data>

<data>FERT</data>

<data>B8845</data>

<data>product a</data>

</sourcemessage>

This needs to be mapped in the following format,

<targetmessage>

<product>

<category>AGRO</category>

<id>A3334</id>

<description>product 1</description>

</product>

<product>

<category>FERT</category>

<id>B8845</id>

<description>product a</description>

</product>

</targetmessage>

Every 3 nodes in the source structure makes one product node on the target. is there a way, you can do this in graphical mapping (with or without user defined functions)?

Thanks,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi TheZone !

You could do this with graphical mapping, using 3 advanced user defined functions that receives the whole queue. Each one of this function retains only the data that corresponds to the expected field... for e.g. one function getCategory that keeps the 1st, 4th, 7th, etc record and outputs this values...then you could map the output of this function to the "Category" target field. The same for the other 2 fields..for getID, it should keep the 2nd, 5th, 8th, and so on..

Just an idea...will try to think something easier or more performant.

Regards,

Matias.

Former Member
0 Kudos

Hi Matias,

How will the user defined function create multiple product nodes - since the number of <data> nodes from the source side are not fixed, and hence the number of product nodes will be number of <data> nodes / 3.

Thanks.

Former Member
0 Kudos

Hey

can you please tell us how have u created the Data type for this.

is it like this?

<sourcemessage>

<data>aaaaaa</data> occurence 1-unbounded

</sourcemessage>

Thanx

Ahmad

Former Member
0 Kudos

Hi thezone !!

Each UDF will create only one type of node...

You need to create 3 advanced udfs and map this way:

- getCategory: sourcemessage/data -> targetmessage/product/category

- getID: sourcemessage/data -> targetmessage/product/id

- getDescription: sourcemessage/data -> targetmessage/product/description

or clearly:

sourcemessage/data -> getCategory -> targetmessage/product/category

sourcemessage/data -> getID -> targetmessage/product/id

sourcemessage/data -> getDescription -> targetmessage/product/description

all 3 udfs will receive a queue with all source data..the difference is that inside each function, you will keep those records you need in order to build the output only based on the data that that function should output..

e.g. getCategory (in pseudo code)

for (i=0;i<data.length;i++)

{

if (i module 3 == 0) //this will be true for i=0, i=3, i=6, etc.

{

ResultList.addValue(data<i>);

}

}

this function will return a list of the category data nodes only...

for the other 2 functions you need to change the "if" so it will be true for i=1, i=4, i=7, etc. for "ID" and the if should be true for i=2, i=5, i=8, etc. for "description".

Regards,

Matias.

Message was edited by:

Matias Denker

justin_santhanam
Active Contributor
0 Kudos

Hello,

You need 4 UDF's in order to achieve the same.

<b>UDF 1</b>[Cache:Queue, My Input parameter name is Data]

int len =Data.length;

for(int j=0;j<len/3;j++)

{

result.addValue("");

}

<b>UDF 2</b>[Cache:Queue, My Input parameter name is Data]

int len =Data.length;

for(int j=0;j<len;j+=3)

{

result.addValue(""Data[j]"");

result.addContextChange();

}

<b>UDF 3</b>[Cache:Queue, My Input parameter name is Data]

int len =Data.length;

for(int j=1;j<len;j+=3)

{

result.addValue(""Data[j]"");

result.addContextChange();

}

<b>UDF 4</b>[Cache:Queue, My Input parameter name is Data]

int len =Data.length;

for(int j=2;j<len;j+=3)

{

result.addValue(""Data[j]"");

result.addContextChange();

}

Now Mapping Logic:

Data -


>UDF1---->Product

Data--->UDF2--->Category

Data-->UDF3-->ID

Data-->UDF4--->Desc.

Hope it helps!!!!

Best regards,

raj.

Answers (0)