IBM Sterling Transformation Extender

Sterling Transformation Extender

Come for answers, stay for best practices. All we're missing is you.


#Sterling
#Supplychain
 View Only
Expand all | Collapse all

Merging two nodes into a single node - Single Input Card

  • 1.  Merging two nodes into a single node - Single Input Card

    Posted 06/24/09 04:24 PM

    Originally posted by: SystemAdmin


    Scenario:

    Input format - has a granular concept of Children and Kids.

    The target format is less granular and are simple. Just got ListOfPeople.

    We want to take all Children and Kids and map them into <People>

    Input:
    <?xml version="1.0" encoding="UTF-8"?>
    • <Header>*
    • <id>1234</id>*
    • <name>CAT</name>*
    • *
    • <ListOfChild>*
    • <Child>*
    • <childName>jack</childName>*
    • <childAge>1</childAge>*
    • <childWeight>6</childWeight>*

    • </Child>*
    • <Child>*
    • <childName>john</childName>*
    • <childAge>2</childAge>*
    • <childWeight>8</childWeight>*

    • </Child>*
    • </ListOfChild>*

    • <ListOfKids>*
    • <Kids>*
    • <kidName>mike</kidName>*
    • <kidAge>11</kidAge>*
    • <kidWeight>80</kidWeight>*

    • </Kids>*
    • <Kids>*
    • <kidName>tom</kidName>*
    • <kidAge>12</kidAge>*
    • <kidWeight>90</kidWeight>*

    • </Kids>*
    • <ListOfKids>*

    • </Header>*

    Output:
    <?xml version="1.0" encoding="UTF-8"?>
    • <Header>*
    • <x>abc</x>*
    • <y>1234</y>*
    • *
    • <ListOfPeople>*
    • *
    • <People>*
    • <Name>jack</Name>*
    • <Age>1</Age>*
    • <Weight>6</Weight>*

    • </People>*
    • <People>*
    • <Name>jack</Name>*
    • <Age>1</Age>*
    • <Weight>6</Weight>*

    • </People>*
    • <People>*
    • <kidName>mike</kidName>*
    • <kidAge>11</kidAge>*
    • <kidWeight>80</kidWeight>*

    • </People>*
    • <People>*
    • <kidName>tom</kidName>*
    • <kidAge>12</kidAge>*
    • <kidWeight>90</kidWeight>*

    • </People>*
    • </ListOfPeople>*

    • </Header>*

    Problem:
    In WTX you have only one rule in the target type tree with the <People> element.
    How can you tell it to take any Children or Kids and turn them into list of People.
    Haven’t been able to find any merge in WTX, so looking for a pattern that merges XML node sets.
    I tried creating three output cards & one input card. One for Header, second one for Children & third one for Kids. So this generates 3 output xmls.
    How do i merge these three output Cards so that i will get one merged output XML?

    Many thanks in advance.
    #IBMSterlingTransformationExtender
    #IBM-Websphere-Transformation-Extender
    #DataExchange


  • 2.  Re: Merging two nodes into a single node - Single Input Card

    Posted 06/25/09 07:14 AM

    Originally posted by: phil2030


    It isn't very pretty but based on what you have, create a simple type tree with the following structure:
    
    ResultXML Header PersonsFromChildren PersonsFromKids
    


    Then simply assign the rules in the map editor on your 4th output card:
    
    ResultXML Header               =PACKAGE(<whatever your header output card is called>) PersonsFromChildren  =PACKAGE(<whatever your children output card is called>) PersonsFromKids      =PACKAGE(<whatever your kids output card is called>)
    


    Put the root element info in the initiator/terminator of ResultXML or add startTag/endTag items and assign rules to provide the xml tags in the resulting output.
    Or, if you have this situation occurring regularly, you could have a simple generic type tree of a "Document" containing any number of "Element"(s) (each being text and unlimited in size) and then create indexes in your maps to assign each of the package rules...
    #IBM-Websphere-Transformation-Extender
    #DataExchange
    #IBMSterlingTransformationExtender