When you need to filter data, or get a value conditionally, you can use one of the following component types:
•Filter: Nodes/Rows ( )
•If-Else Condition ( )
You can add these components to the mapping either from the Insert menu, or from the Insert Component toolbar. Importantly, each of the components above has specific behavior and requirements. The differences are explained in the following sections.
When you need to filter data, including XML nodes, use a Filter Nodes/Rows component. The Filter Nodes/Rows component enables you to retrieve a subset of nodes from a larger set of data, based on a true or false condition. Its structure on the mapping area reflects this:
In the structure above, the condition connected to bool determines whether the connected node/row goes to the on-true or on-false output. Namely, if the condition is true, the node/row will be redirected to the on-true output. Conversely, if the condition is false, the node/row will be redirected to the on-false output.
When your mapping needs to consume only items that meet the filter condition, you can leave the on-false output unconnected. If you need to process the items that do not meet the filter condition, connect the on-false output to a target where such items should be redirected.
For a step-by-step mapping example, see Example: Filtering Nodes.
If you need to get a single value (not a node or row) conditionally, use an If-Else Condition. Note that If-Else conditions are not suitable for filtering nodes or rows. Unlike Filter Nodes/Rows components, an If-Else Condition returns a value of simple type (such as a string or integer). Therefore, If-Else Conditions are only suitable for scenarios where you need to process a simple value conditionally. For example, let's assume you have a list of average temperatures per month, in the format:
An If-Else Condition would enable you to return, for each item in the list, the value "high" if temperature exceeds 20 degrees Celsius, and value "low" if temperature is lower than 5 degrees Celsius.
On the mapping, the structure of the If-Else Condition looks as follows:
If the condition connected to bool is true, then the value connected to value-true is output as result. If the condition is false, the value connected to value-false is output as result. The data type of result is not known in advance; it depends on the data type of the value connected to value-true or value-false. The important thing is that it should always be a simple type (string, integer, and so on). Connecting input values of complex type (such as nodes or rows) is not supported by If-Else Conditions.
If-Else Conditions are extendable. This means that you can add multiple conditions to the component, by clicking the Add ( ) button. To delete a previously added condition, click the Delete ( ) the button. This feature enables you to check for multiple conditions and return a different value for each condition, if it is true.
Expanded If-Else Conditions are evaluated from top to bottom (first conditions is checked first, then the second one, and so on). If you want to return a value when none of the conditions are true, connect it to otherwise.
For a step-by-step mapping example, see Example: Returning a Value Conditionally.