cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping logic

amarnath_m
Explorer
0 Kudos

Hello experts

I have following requirements. Please suggest to resolve it.

Source : <ParentNode>

               <Field1>

               <Field2>

               <Field3>

               <Field4>

               <Field5>

               <Field6>

               <Field7>

               <Field8>

             <ParentNode>


Target: <ParentNode>

               <Field3>

               <Field5>

               <Field3>

               <Field5>

            <ParentNode>


I have given you source structure.. And me desired target is given.. Please help me how to achieve this..


Regards

Amarnath..

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor
0 Kudos

Hi Amarnath!

Regards, Evgeniy.

amarnath_m
Explorer
0 Kudos

Hi Evgeniy

Your code is helpful. But the concern over here is, in the output i will get Field1, Field2 as well..

So it should be like,

Field1

Field2

Field3

Field5

Field3

Field5

Please help for this logic..

Regards

Amar

former_member190293
Active Contributor
0 Kudos

Hi Amarnath!

You can simply change ocurence of Field3 to 0..unbounded and duplicate it three more times in your result structure:

Or use existing nodes Field3,..., Field8 to append values of source fields.

Regards, Evgeniy.

amarnath_m
Explorer
0 Kudos

Hi Evgeniy

Incase of Field3 is element, the udf works fine.

But consider Field3 and Field5 as Elements and there are lot of sub-elements to it.. structure like,

Field3

     @attributes

     Field31

     Field32

     Field33

Field5

     @attributes

     Field51

     Field52

     Field53

Please help out..

Regards

Amar..

former_member190293
Active Contributor
0 Kudos

Hi Amarnath!

Your current requirement is completely different against original.

You can use XSLT or Java mapping for it.

Regards,  Evgeniy.

former_member190293
Active Contributor
0 Kudos

Hi Amarnath!

Actualy, there is one one "tricky" way to achieve your requirement.

1. Change UDF code to this:

2. Use following mapping:

All your "Field" elements in this mapping should be used with option "Return as XML". And standard function "replaceString" is intended for removing <?xml version="1.0" encoding="UTF-8"?> XML declaration from concatenated tree fragment.

Result:

Regards, Evgeniy.

former_member182412
Active Contributor
0 Kudos

Hi Amarnath,

Can you tell us what is the reason for this requirement? is your receiver is file adapter?? are you using file content conversion??

Regards,

Praveen.

Answers (3)

Answers (3)

jnyholt
Explorer
0 Kudos

The following XSLT should work:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="ParentNode">

        <xsl:copy>

            <xsl:copy-of select="Field3"/>

            <xsl:copy-of select="Field5"/>

            <xsl:copy-of select="Field3"/>

            <xsl:copy-of select="Field5"/>

        </xsl:copy>

    </xsl:template>

</xsl:stylesheet>

manoj_khavatkopp
Active Contributor
0 Kudos

Use same Message type as source and target in mapping and just Map the required Fields i.e in you case Field3 and Field5 as below.

Now in Operation Mapping after this mapping include a simple java Mapping  to remove the Parent Node i.e in the above screenshot Records.

Br,

Manoj

former_member186851
Active Contributor
0 Kudos

Hello Amarnath,

Try like below

Field3---->CopyValue---->Field3

If you wish to copy the first value only.

If you can post the queue value can assist further.

amarnath_m
Explorer
0 Kudos

Hi Raghu

CopyValue will work..

But the case is, sometime Field3 may come and maynot come..

So copyvalue will result in error..

Regards

Amar

former_member186851
Active Contributor
0 Kudos

Hello Amarnath,

Try like below

Field3------>Exists-------->If----------------------------------->Field3

    Copyvalue-------------->then

In the else part add as per the requirement.

amarnath_m
Explorer
0 Kudos

Hi raghu

Tried all possibilities..

But the Target structure is varying.. Output comes like,

Field3

Field3

Field5

Field5

But the output sequence should not vary..

former_member186851
Active Contributor
0 Kudos

Hello Amarnath,

Please post the queue values.

Ryan-Crosby
Active Contributor
0 Kudos

Hi Amarnath,

Meaning the one thing you are looking for is this output ordering?

field3

field5

field3

field5

instead of:

field3

field3

field5

field5

If so, you would need to write some special UDF logic as part of a graphical mapping, a java mapping, or some combination of both to achieve that.

Regards,

Ryan Crosby