User GuideReference ManualIntegration Scenarios
 

2.3.2. Filter Function

See: Managing Channels - Message Transformation Functions

The Filter function is used to specify if the mapping result will be used as an output or not.

You can add a Filter function as an Xpath expression to any mapping rule to filter the output of this mapping rule, that is to decide if the result is output or not in the generated message out. Note that the Filter function will always return an element, but if the filtering condition is not met, this output will be empty.

The Filter can be used on any element but is most useful to filter loop elements and to generate only some of these elements according to the filter rule as illustrated in the following examples.

  • The Filter is done on the mapped element, that means that the filter context is the mapped element and that it can be immediately referenced using a ' . ' in the filtering Xpath expression.

  • The Filter function is applied on the mapped element and always returns a result. That is not the case for the If function that is applied before the mapping, meaning that, if the condition is not met, the mapping is not performed. See the If Function chapter for more details.

Filter example on a value node

In the following example, the node mapping is filtered on the Price value and the mapping output is used only if it is greater than 12 (Xpath filter expression is ' .>12 ').

Input csv file:

Code, Quantity, Price
A23, 2, 12.5
A24, 3, 10.0
A25, 1, 15.2
A26, 2, 13.6
Filter example mapping

Figure 2.45. Filter example mapping


In the second ligne, the Price is lower than the filter value and the mapping output will be empty. Note that the output is generated and so the separating comma is present (as opposed to If function output).

Output csv file:

Code, Quantity, Price
A23, 2, 12.5
A24, 3,
A25, 1, 15.2
A26, 2, 13.6

Filter example on a loop node

In the following example, the entire line mapping is filtered on the Price value and the mapping output is used only if it is greater than 12 (Xpath filter expression is ' field[3]>12 ').

Filter example mapping

Figure 2.46. Filter example mapping


Now, using the same input file as in the previous example, the entire second line, for which the Price is lower than the filter value is not output in the out message file.

Output csv file:

Code, Quantity, Price
A23, 2, 12.5
A25, 1, 15.2
A26, 2, 13.6