IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Defining and transforming data > Transforming data > Transforming data using XML maps > XML mapping examples

Example: Append the result of two or more input arrays into an output array

You can append two or more input arrays of the same or different types to produce one output array of the same or different type.

For example, the Star travel agency groups its members into gold star clients and silver star clients. Gold star clients earn reward points for their frequent flying while silver star clients do not earn points. The business object TravelAgencyA contains two array elements;goldStar_client and silverStar_client, as shown below:

The Cheap Travels agency provides the same service to all clients, and so the business object TravelAgencyB contains one array element, client, as shown below:

Both agencies are owned by the same company, which wants to inform all their clients of upcoming deals. To create a combined list of all members who should receive flyers for an upcoming promotion, combine all gold client members and all silver client members from Star Travel with all clients of the Cheap Travels agency.

To achieve this scenario, create an Append transform between the input array elements goldStar_client and silverStar_client in TravelAgencyA and the output array element client in TravelAgencyB .

First, create an XML map with TravelAgencyA as the input business object and TravelAgencyB as the output business object. Then create an Append transform with goldStar_client and silverStar_client as the input elements, and client as the output element.

When the Append transform is first created, notice that there is a warning

indicating that some nested transforms do not yet exist. Therefore, there is more work that needs to be done before the Append transform is fully constructed.

Edit the Append transform by double clicking on it or by clicking on the Edit icon on the upper-right of the transform icon.

. The following transforms have been automatically created for the given situation.

Notice that you cannot expand the arrays here to create a mapping. This is because the mapping must be created in the nested For each transform. (The For each transform gives the same warning indication as before in which some nested transforms do no yet exist).

Edit the For each transform to define the mapping from gold star clients to general clients. In this example, we will simply move firstname and lastname information. The rewardPoints information is not used in the example.

Now that the mappings of the For each transform is defined, move back up one nesting map level. The warning has gone away.

There is no need to change the Move transform at this nested level since it performs the required result of copying the silver star client information over to the target which is of the same complex type. Move up one nested mapping level once more. The warning on the Append transform has now gone away. The Append transform is complete.

Run this map with the following input data:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:TravelAgencyA xmlns:ns0="http://FindTravelDestinationAp" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <goldStar_client>
    <firstname>John</firstname>
    <lastname>Smith</lastname>
    <rewardPoints>10476</rewardPoints>
  </goldStar_client>
  <goldStar_client>
    <firstname>Kathy</firstname>
    <lastname>Jennings</lastname>
    <rewardPoints>14872</rewardPoints>
  </goldStar_client>
  <goldStar_client>
    <firstname>Bill</firstname>
    <lastname>Cunningham</lastname>
    <rewardPoints>3413</rewardPoints>
  </goldStar_client>
  <silverStar_client>
    <firstname>Robert</firstname>
    <lastname>Meyers</lastname>
  </silverStar_client>
  <silverStar_client>
    <firstname>Sue</firstname>
    <lastname>Berton</lastname>
  </silverStar_client>
</ns0:TravelAgencyA>

The result is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<io:TravelAgencyB xmlns:io="http://FindTravelDestinationAp" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <client>
    <firstname>John</firstname>
    <lastname>Smith</lastname>
  </client>
  <client>
    <firstname>Kathy</firstname>
    <lastname>Jennings</lastname>
  </client>
  <client>
    <firstname>Bill</firstname>
    <lastname>Cunningham</lastname>
  </client>
  <client xmlns:ns0="http://FindTravelDestinationAp">
    <firstname>Robert</firstname>
    <lastname>Meyers</lastname>
  </client>
  <client xmlns:ns0="http://FindTravelDestinationAp">
    <firstname>Sue</firstname>
    <lastname>Berton</lastname>
  </client>
</io:TravelAgencyB>

The resulting output shows that gold star and silver star clients have been appended together. The order of the output is all the gold star clients and then all the silver star clients.

To change the order in which the input information is appended in the output element, simply change the order of the Append inputs by using the Order property page. The following image shows that the order of the input elements has been changed and silver star clients are now the first input to the Append transform:

As a result, the Append transform is updated in the editor to reflect this change. Notice that the silver star connection is now the first input to the Append transform.

Run this map now with the same input data. The following output is generated. Notice here that the silver star client information comes before the gold star client information.

<?xml version="1.0" encoding="UTF-8"?>
<io:TravelAgencyB xmlns:io="http://FindTravelDestinationAp" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <client xmlns:ns0="http://FindTravelDestinationAp">
    <firstname>Robert</firstname>
    <lastname>Meyers</lastname>
  </client>
  <client xmlns:ns0="http://FindTravelDestinationAp">
    <firstname>Sue</firstname>
    <lastname>Berton</lastname>
  </client>
  <client>
    <firstname>John</firstname>
    <lastname>Smith</lastname>
  </client>
  <client>
    <firstname>Kathy</firstname>
    <lastname>Jennings</lastname>
  </client>
  <client>
    <firstname>Bill</firstname>
    <lastname>Cunningham</lastname>
  </client>
</io:TravelAgencyB>

Although this example only focused on array element inputs, Append transforms can be used whenever their are multiple inputs that need to be mapped to an array target. Therefore, the Append transform can also be used when multiple non-array elements target an output array element.

XML mapping examples