Filters and Conditions

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Designing Mappings >

Filters and Conditions

When you need to filter data, or get a value conditionally, you can use one of the following component types:

 

Filter: Nodes/Rows ( mff_ic_insert_filter )
If-Else Condition ( mff_ic_if_else )

 

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.

 

Filtering nodes or rows

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:

mff_filter_component

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 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.

 

Returning a value conditionally

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:

 

<Temperatures>  
  <data temp="19.2" month="2010-06" />
  <data temp="22.3" month="2010-07" />
  <data temp="19.5" month="2010-08" />
  <data temp="14.2" month="2010-09" />
  <data temp="7.8" month="2010-10" />
  <data temp="6.9" month="2010-11" />
  <data temp="-1.0" month="2010-12" />
</Temperatures>

 

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:

ifelse-extend01

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 ( gui_add_function_parameter ) button. To delete a previously added condition, click the Delete ( gui_delete_function_parameter ) the button.  This feature enables you to check for multiple conditions and return a different value for each condition, if it is true.

mff_if_else_extendable

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.


© 2019 Altova GmbH