createIf
You use createIf() to create a tag in the target structure depending on a condition.
In the example below, a mapping is required between two different formats for a list of messages. The attribute type is used in the source structure to classify the message as either internal (type=“internal”) or external (type=“external”). However, in the target structure the tag internalRequest or externalRequest is used:
Source Structure (Left) and Target Structure (Right)
Field Name |
minOccurs |
maxOccurs |
Field Name |
minOccurs |
maxOccurs |
RequestListMsg |
1 |
1 |
RequestListEIMsg |
1 |
1 |
request |
0 |
unbounded |
internalRequest |
0 |
unbounded |
type (Attr.) |
1 |
1 |
initiator |
1 |
1 |
creator |
1 |
1 |
contact |
1 |
1 |
contact |
1 |
1 |
issue |
1 |
1 |
description |
1 |
1 |
externalRequest |
0 |
unbounded |
|
|
|
initiator |
1 |
1 |
|
|
|
contact |
1 |
1 |
|
|
|
issue |
1 |
1 |
You use createIf() to create the respective target field depending on attribute type:
Message Mapping Using createIf()
Target Field Mapping |
Value of Constant() |
/RequestListEIMsg=/RequestListMsg |
|
/RequestListEIMsg/internalRequest= |
internal |
/RequestListEIMsg/internalRequest/initiator= |
|
/RequestListEIMsg/internalRequest/contact= |
|
/RequestListEIMsg/internalRequest/issue= |
|
/RequestListEIMsg/internalRequest= |
external |
/RequestListEIMsg/externalRequest/initiator= |
|
/RequestListEIMsg/externalRequest/contact= |
|
/RequestListEIMsg/externalRequest/issue= |
|

The function removeContexts() is required because the attribute type is mapped in place of the source field request. Therefore, there is no target field for requestand no context in the target structure. However, the type queue has nevertheless saved the request context, so processing would terminate early if you did not delete this context.
Source Instance |
Result |
<?xml version="1.0" <RequestListMsg> <request type="internal"> <creator> </request> <request type="external"> <creator> </request> </RequestListMsg> |
<?xml version="1.0" <ns0:RequestListEIMsg <internalRequest> <initiator> </internalRequest> <externalRequest> <initiator> </internalRequest> </ns0:RequestListEIMsg> |