Skip to Content
avatar image
Former Member

Context mapping issue

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 26, 2011 at 08:08 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Feb 15, 2011 at 03:49 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 15, 2011 at 10:49 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • avatar image
    Former Member
    Jun 07, 2011 at 01:44 PM

    Solved using XSLT mapping.

    Thanks all for your help.

    Add comment
    10|10000 characters needed characters exceeded