ForEach Mediator
The ForEach mediator requires an XPath expression and a sequence (inline or referred). It splits the message into a number of different messages derived from the original message by finding matching elements for the XPath expression specified. Based on the matching elements, new messages are created for each iteration and processed sequentially. The processing is carried out based on a specified sequence. The behaviour of ForEach mediator is similar to a generic loop. After mediation, the sub-messages are merged back to their original parent element in the original message sequentially.
The ForEach mediator creates the following properties during mediation.
Property | Description |
|---|---|
FOREACH_ORIGINAL_MESSAGE | This contains the original envelop of the messages split by the ForEach mediator. |
FOREACH_COUNTER | This contains the count of the messages processed. The message count increases during each iteration. |
Syntax
<foreach expression="xpath" [sequence="sequence_ref"] [id="foreach_id"] >
<sequence>
(mediator)+
</sequence>?
</foreach>Configuration
The parameters available to configure the ForEach mediator are as follows.
Parameter Name | Description |
|---|---|
ForEach ID | If a value is entered for this parameter, it will be used as the prefix for the |
Expression | The XPath expression with which different messages are derived by splitting the parent message. This expression should have matching elements based on which the splitting is carried out. You can click NameSpaces to add namespaces when you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. |
Sequence | The mediation sequence that should be applied to the messages derived from the parent message. ForEach mediator is used only for transformations, thereby, you should not include Call , Send and Callout mediators, which are used to invoke endpoints, in t his sequence. You can select one of the following options.
|
Examples
In this configuration, the //m0:getQuote/m0:request" XPath expression evaluates the split messages to be derived from the parent message. Then the split messages pass through a sequence which includes a Log mediator with the log level set to full.
Sample
See Sample 18: Transforming a Message Using ForEach Mediator.