removeContexts
You use removeContexts() to delete all the top contexts for an element. This removes all top hierarchy levels, so that all elements of the target queue are assigned to a root element of the source queue.
In the example below, a list of debtors with a payment field containing one or more payments made for each debtor is to be transformed into a list that only contains payments made. The payments and the debtors also each have the attribute id to help identify them.
Source Structure (Left) and Target Structure (Right)
Field Name |
minOccurs |
maxOccurs |
Field Name |
minOccurs |
maxOccurs |
DebitorListMsg |
1 |
1 |
AllDebtsMsg |
1 |
1 |
Debitor |
0 |
unbounded |
debt |
0 |
unbounded |
id (Attr) |
|
|
id (Attr) |
1 |
1 |
payment |
1 |
unbounded |
|
|
|
id (Attr) |
|
|
|
|
|
To delete the top hierarchy level Debitor, connect the element payment to the function removeContexts(). Specify as the target field the field into which you want the contents of payment to be copied, in this case debt.
Message Mapping Using removeContexts()
Target Field Mapping |
/AllDebtsMsg=/DebitorListMsg |
/AllDebtsMsg/debt=removeContexts(/DebitorListMsg/Debitor/payment) |
/AllDebtsMsg/debt/id=/DebitorListMsg/Debitor/payment/id |
Source Instance |
Result |
<?xml version="1.0" <DebitorListMsg> <Debitor id="1"> <payment id="1"> </Debitor> <Debitor id="2"> <payment id="4"> </Debitor> <Debitor id="3"> <payment id="5"> </Debitor> </DebitorListMsg> |
<?xml version="1.0" <ns0:AllDebtsMsg
<debt id="1">
<debt id="4">
<debt id="5">
</ns0:AllDebtsMsg> |