cancel
Showing results for 
Search instead for 
Did you mean: 

Help with mapping

former_member190543
Participant
0 Kudos

Hi guys,

I have a mapping requirement and I am stuck. Can you help please?

Source structure:

Item (0 to Unbounded)

  Channel (0 to 4)

      Name

         Segment

            id (0 to 1)

Target structure:

Idoc_Segment_01  (0 to Unbounded)

    Data

       Field1  (0 to 1)

       Field2  (0 to 1)

       Field3  (0 to 1)

       Field4  (0 to 1)

Mapping:

1. Item mapped to Idoc_Segment_01

2. For a "Channel", if its Name equals "a", map its corresponding "id" to Field1

3. For a "Channel",If its Name equals "b", map its corresponding "id" to Field2

4. For a "Channel",If its Name equals "c", map its corresponding "id" to Field3

5 For a "Channel",If its Name equals "d", map its corresponding "id" to Field4

If I do direct mapping using If function, I have a problem when once of the optional Source node ("Channel") is absent. It is then taking the value of first occurence of "id" and populating in the first node of the target, but I want it to populate in the corresponding target node.

--------------------------------------------------------------------------------------

For example:

Source data is:

Item

   Channel

    a

      segment

         kX1

Channel

    b

      segment

         kX2

Channel

    c

      segment

         kX3

Item

Channel

   a

     segment

        kY1

Channel

   b

     segment

        kY2

Channel

   c

     segment

        kY3

Channel

   d

     segment

        kY4

----------------------------------------------------------------

Result I am getting:

The result I am getting is:

Idoc_Segment_01

   Data

     kX1

     kX2

     kX3

     kY4

   Data

     kY1

     kY2

     kY3

------------------------------------------------------------------------

Result I want should be:

Idoc_Segment_01

   Data

     kX1

     kX2

     kX3

   Data

     kY1

     kY2

     kY3

     kY4

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Ramesh,

Use below mapping for all four fields.

Name and ID fields context changed to Item node.

Regards,

Praveen.

former_member190543
Participant
0 Kudos

Hi Praveen,

Many thanks for your input. I tried this mapping which is producing the correct values. The problem I have is that "Item" occurs many times and it does not have all 4 "Channels" every time. In the below example, Channel occurs only 3 times in first Item and 4 times in second Item. So with this mapping what I am getting is array of [] [] [] [] [] [] [KY4] but what I want is [] [KY4] that is same number of Item segments. If I am confusing you, please let me know and I will email you the xml.


Item (0 to Unbounded)

  Channel

      Name

         Segment

            id

  Channel

      Name

         Segment

            id

Channel

      Name

         Segment

            id

Item (0 to Unbounded)

  Channel

      Name

         Segment

            id

  Channel

      Name

         Segment

            id

Channel

      Name

         Segment

            id

Channel

      Name

         Segment

            id

Kind regards,

Ramesh.

former_member182412
Active Contributor
0 Kudos

Hi Ramesh,

Did you change context of Name and ID fields? Context should be changed to Item for both fields.

I have tested it is working as you expected.

Source XML:


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

<ns0:MT_Sender xmlns:ns0="urn:gp:prototype">

   <Item>

      <Channel>

         <Name>a</Name>

         <Segment>

            <ID>kX1</ID>

         </Segment>

      </Channel>

      <Channel>

         <Name>b</Name>

         <Segment>

            <ID>kX2</ID>

         </Segment>

      </Channel>

      <Channel>

         <Name>c</Name>

         <Segment>

            <ID>kX3</ID>

         </Segment>

      </Channel>

   </Item>

   <Item>

      <Channel>

         <Name>a</Name>

         <Segment>

            <ID>kY1</ID>

         </Segment>

      </Channel>

      <Channel>

         <Name>b</Name>

         <Segment>

            <ID>kY2</ID>

         </Segment>

      </Channel>

      <Channel>

         <Name>c</Name>

         <Segment>

            <ID>kY3</ID>

         </Segment>

      </Channel>

      <Channel>

         <Name>d</Name>

         <Segment>

            <ID>kY4</ID>

         </Segment>

      </Channel>

   </Item>

</ns0:MT_Sender>

Traget XML:


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

<ns0:MT_Target xmlns:ns0="urn:gp:prototype">

   <Data>

      <Field1>kX1</Field1>

      <Field2>kX2</Field2>

      <Field3>kX3</Field3>

   </Data>

   <Data>

      <Field1>kY1</Field1>

      <Field2>kY2</Field2>

      <Field3>kY3</Field3>

      <Field4>kY4</Field4>

   </Data>

</ns0:MT_Target>

If your source xml differs then paste your source xml in this thread.

Regards,

Praveen.

former_member190543
Participant
0 Kudos

Hi Praveen,

I previously did not change the context for the Name field. Now I did and it works perfectly.

Thank you so much.

Regards,

Ramesh.

Answers (0)