on 01-26-2011 5:58 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Solved using XSLT mapping.
Thanks all for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.