Liquid XML Studio
See Also Send Feedback
Data Mapping > Data Mapper Functions > By Category > Logic > Or

Glossary Item Box

Function Name
Return the logical "or" of multiple input values
Input 1 First input value to test as a boolean
Value 2 Second input value to test as a boolean
Result Boolean indicator - true if any of the inputs evaluate to true
None -


The Data Mapper Logic Or function allows you to carry out conditional "or" tests on your input data and on information processed from it. By default the function tests two inputs, but you can add additional inputs as you require. The Or function allows you to implement conditional control on the set of data items you map and the details of how you map it. The Or function will output a value of true if any of the input values are true. Only one input value has to be true for the Or function to output a true value - it will only output a false value if all input values are false. As soon as the Mapper encounters a true input, it stops testing and outputs true. Since the Or function outputs a boolean value, you are likely to use it in conjunction with other functions in the Set, Logic and Comparator categories. To apply the Logic Or function, use the following process:

Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using staff_source.xsd, an XML Schema Definition inferred from the following source:

Source XML Copy Code

For our target schema we will be using staff_target.xsd, inferred from the following XML:

Target XML Copy Code
 <staff_member since="2000" contract="false">
 <staff_member since="2003" contract="true">
 <staff_member since="1998" contract="false">

The data models employees within an organisation. Let's assume that, rather than mapping all data values, we only want to map "employee" elements representing staff members who either have permanent contracts or who began working at the company before 2000. Here is the Data Mapper with Source and Target imported:

Data Mapper Source and Target

Drag the Logic Or function from the Component Palette into the mapping area:

Or Component

Or Added

The Or function takes two inputs by default, but you can add extra inputs by right-clicking any of the existing inputs as the component appears in the Mapper, choosing Add Above or Add Below. If any of your inputs are not connected, the Mapper will simply ignore them. The inputs all represent boolean values, or values that the Mapper can cast to booleans. The function output will be true if any inputs are evaluated as true. The function output will be false only if all of the inputs are false. Both inputs and output of the Or function may be connected to items in the XML Reader/ Writer or other components in the Mapper.

Since we want to map "employee" elements if they represent permanent staff, connect the "permanent" output in the XML Reader to one of the Or inputs.

Reader to Or

We also want to map records for employees who started before 2000, so drag a Less Than component from the Comparator section onto the Mapper. Connect its Value 1 input to the "started" output in the XML Reader, since this is the value we want to be less than 2000 for this particular part of the conditional test.

Reader to Less Than

Now we need to define the value to compare the input start date to. Drag a Constant Value from the Data Type section onto the Mapper. Right-click it and choose Show Properties. Enter an integer as the Data Type and the number 2000 as the Value.

Constant Properties

Connect the Constant output to the Value 2 input in the Less Than function.

Constant to Less Than

Now each time the Mapper encounters the "started" element when it carries out this part of the test, it will check whether the number is less than 2000. If a start date is before 2000, the function will output a value of true, otherwise it will output a value of false. Connect the Less Than function output to the second input of the Or function.

Less Than to Or

Now the Or output will be true either if the "started" element is less than 2000 or the "permanent" value is true. Let's now use this information to filter our data. Drag a Filter function from the Set section onto the Mapper. Connect its Bool input to the output of the Or function and its Nodes input to the "employee" output in the XML Reader.

Filter Added

Now connect the output of the Filter function to the "staff_member" input in the XML Writer. This will ensure that an "employee" element is mapped if its "started" element is less than 2000 or its "permanent" value is true. No other "employee" elements will be mapped.

Filter to Writer

Finally let's make the remaining input and output connections. Remember to map "started" to "since" and "permanent" to "contract" - although we have used these values from the source we have not yet instructed the Mapper to map them.

Inputs and Outputs Connected

We can now execute the transform by pressing Shift-F5 or the Execute button (Execute). The transform is applied and the file we selected as output opens in the editor:

Output XML Copy Code
 <staff_member since="2001" contract="true">
 <staff_member since="1998" contract="true">
 <staff_member since="1999" contract="false">

The output only contains those "staff_member" elements with start dates before 2000 or permanent contracts (or both).

If you are adding extra inputs to the Or function by right-clicking an existing input and selecting Add Above or Add Below, you can control the order in which the Mapper carries out the conditional tests. When the Mapper encounters a true input, it does not check any remaining inputs as the output value must be true. In each case, the Mapper will only reach the final test defined if all preceding inputs have returned false.
If the Or function receives an input value that is not a boolean, it will attempt to cast it.

This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

See Also





Data Mapping
Variable Function Inputs