cancel
Showing results for 
Search instead for 
Did you mean: 

Context mapping issue

Former Member
0 Kudos

Hi experts,

I have a problem working with contexts in my graphical mapping.

In the source message I have two separeted unbounded structures, but they have to be together in the ouput (one inside the other). The nodes must be joined using a key (number).

I wanted to ask you if you jnow a way to do this using graphical mapping in PI 7.1. I know how to do it with a Java mapping, but I need to avoid that way if it's possible.

Let me show you examples so you can understand it better.

This is my source message:

<input>

<item>

<number>1</number>

<text>abc</text>

</item>

<item>

<number>2</number>

<text>def</text>

</item>

<price_item>

<number>1</number>

<price>1.50</price>

</price_item>

<price_item>

<number>1</number>

<price>3.0</price>

</price_item>

<price_item>

<number>2</number>

<price>5.0</price>

</price_item>

</input>

And this is the expected output, using those values:

<output>

<item>

<number>1</number>

<text>abc</text>

<price_item>

<number>1</number>

<price>1.50</price>

</price_item>

<price_item>

<number>1</number>

<price>3.0</price>

</price_item>

</item>

<item>

<number>2</number>

<text>def</text>

<price_item>

<number>2</number>

<price>5.0</price>

</price_item>

</item>

</output>

Thank you in advance,

LUIS B.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I am assuming that the value of price_item/number is same sequence as the in item/number, the you can use following mapping:

  • All the <item> and its subnodes map to the corresponding nodes

  • input/price_item/number -> removeContext -> SplitByValue(ValueChange) -> output/item/price_item

  • input/price_item/number -> output/item/price_item/number

  • input/price_item/price -> output/item/price_item/price

If your input/price_item/number sequence is different from input/item/number, then you have to do it in different way:

  • input/item -> output/item

  • input/item/number -> removeContext -> Sort -> SplitByValue(eachValue) -> output/item/number

  • input/price_item/number -> removeContext -Sort -> SplitByValue(ValueChange)-> output/item/price_item

  • input/price_item/number -> removeContext -Sort -> SplitByValue(eachValue)-> output/item/price_item/number

  • input/price_item/price -> removeContext ->SortByKey (Key is the input/price_item/number) -> SplitByValue(eachValue)-> output/item/price_item/price

Regards

Liang

Former Member
0 Kudos

Thanks a lot Liang! It works perfectly.

I'll need to implement the second solution, since I'm not sure if the nodes are sorted or not.

Correct if I'm wrong, I'm assumed that I have to use removeContext --> SortByKey --> SplitByValue per each field inside item and price_item, right?

Thanks,

LUIS B.

Former Member
0 Kudos

Hi, Luis:

Yes you are correct.

However, if the field is inside <item>, then your key will be /item/number

If the fields is inside <item_price>, then the key will be /item_price/number.

Regards

Liang

Answers (3)

Answers (3)

Former Member
0 Kudos

Solved using XSLT mapping.

Thanks all for your help.

Former Member
0 Kudos

Hi,

you can try this, so you will syncronyze your value queues with a UDF.


item_text ------------------------------------> output_text

                                 +--------+
item_number -------------------> |        |
                                 | myFunc | --> output_price
                +--------+   --> |        |
price_number--> |        |   |   +--------+
                | concat | --
price_price --> |        |
                +--------+ 

Pseudocode of myFunc is very simple. You read your item queue and for each element search his price. If it does not exist then write a blank. So you will have a price queue sorted like your item queue, and a blank value when his partner does not exist.

Regards.

Former Member
0 Kudos

>> If it does not exist then write a blank

I guess non-existant nodes are not being reflected in his queue. So this suggestion brings us back to original problem? )

rgds

gab

Former Member
0 Kudos

Non exist nodes are detected when you have a items number witch have not their price number.

In UDF you review all items number and search their corresponding price number. If you have a item number and you don't find his price number, then you must write a blank. So, you will have two output value queues of identical size.

Regards.

Former Member
0 Kudos

Hi again,

I have another issue with this case.

When I have something like the following XML, which an item without a price, this mapping doesn't work.

This is the XML I sent:

<input>

<item>

<number>1</number>

<text>abc</text>

</item>

<item>

<number>2</number>

<text>def</text>

</item>

<price_item>

<number>2</number>

<price>5.0</price>

</price_item>

</input>

And I got this:

<output>

<item>

<number>1</number>

<text>abc</text>

<price_item>

<number>2</number>

<price>5.0</price>

</price_item>

</item>

<item>

<number>2</number>

<text>def</text>

</item>

</output>

As you can see, the price item went to item 1 instead of item 2.

Could you help me with this? Thanks in advance.

LUIS B.

Edited by: Luis Bersier on Feb 15, 2011 4:49 PM

Former Member
0 Kudos

Try using Mapwithdefault node function as,

input/price_item/price ->MapwithDefault--> output/item/price_item/price

Regards

Ramg

Former Member
0 Kudos

Can you try:

  • input/price_item/price -> mapWithDefault(0.00) -> removeContext ->SortByKey (Key is the input/price_item/number) -> SplitByValue(eachValue)-> output/item/price_item/price

Not sure, but see if it works

rgds

gab

Former Member
0 Kudos

Thanks for the help, but it didn't work.

The price item is still sent to the wrong item.

Former Member
0 Kudos

The context of input/price_item/price needs to be set at default level ... can you verify?

rgds

gab