Liquid Studio Documentation
Data Mapping / Data Mapper Functions / By Category / Logic / And
In This Topic
    And
    In This Topic

    Function Name
    And
    Category
    Logic
    Icon
    And
    Description
    Return the logical "and" of multiple input values
    Inputs
    Input 1 First input value to test as a boolean
    Input 2 Second input value to test as a boolean
    Outputs
    Result Boolean indicator - true only if all inputs evaluate to true
    Properties
    None -

    Usage

    The Data Mapper Logic And function allows you to carry out conditional "and" 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 And function allows you to implement conditional control on the set of data items you map and the details of how you map it. The And function will output a value of true if all input values are true. If any of the And inputs are false, the function will output a false result. As soon as the Mapper encounters a false input, it stops testing and outputs false.

    Since the And function outputs a boolean value, you are perhaps likely to use it in conjunction with other functions in the Set, Logic and Comparator categories. To apply the Logic And 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
    <staff>
     <employee>
      <first_name>Mark</first_name>
      <second_name>Brown</second_name>
      <started>2001</started>
      <permanent>true</permanent>
     </employee>
     <employee>
      <first_name>Jane</first_name>
      <second_name>Jackson</second_name>
      <started>1998</started>
      <permanent>true</permanent>
     </employee>
     <employee>
      <first_name>Joe</first_name>
      <second_name>Simpson</second_name>
      <started>2008</started>
      <permanent>true</permanent>
     </employee>
     <employee>
      <first_name>Lynn</first_name>
      <second_name>Nicolson</second_name>
      <started>2008</started>
      <permanent>false</permanent>
     </employee>
    </staff>
    

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

    Target XML
    Copy Code
    <company>
     <staff_member since="2000" contract="false">
      <f_name>Ken</f_name>
      <s_name>Jones</s_name>
     </staff_member>
     <staff_member since="2003" contract="true">
      <f_name>Linda</f_name>
      <s_name>Lee</s_name>
     </staff_member>
     <staff_member since="1998" contract="false">
      <f_name>Paul</f_name>
      <s_name>Mitchell</s_name>
     </staff_member>
    </company>
    

    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 have permanent contracts and who began working at the company in 2000 or later. Here is the Data Mapper with Source and Target imported:

    Data Mapper Source and Target

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

    And Component

    And Added

    The And 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 only be true if all inputs are evaluated as true. The function output will be false if any of the inputs are false. Both inputs and output of the And function may be connected to items in the XML Reader/ Writer or other components in the Mapper.

    Since we want to map only "employee" elements for permanent staff, connect the "permanent" output in the XML Reader to one of the And inputs.

    Reader to And

    We also only want records to be mapped for employees who started in 2000 or later, so drag a Greater Than or Equal 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 at least 2000.

    Reader to Greater Than or Equal

    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 Greater Than or Equal function.

    Constant to Greater Than or Equal

    Now each time the Mapper encounters the "started" element for this part of the conditional test, it will check whether the number is at least 2000. If a date is greater than or equal to 2000, the function will output a value of true, otherwise it will output a value of false. Connect the Greater Than or Equal function output to the second input of the And function.

    Greater Than or Equal to And

    Now the And output will only be true if the "started" element is at least 2000 and 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 And 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 only mapped if its "started" element is at least 2000 and 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
    <company>
     <staff_member since="2001" contract="true">
      <f_name>Mark</f_name>
      <s_name>Brown</s_name>
     </staff_member>
     <staff_member since="2008" contract="true">
      <f_name>Joe</f_name>
      <s_name>Simpson</s_name>
     </staff_member>
    </company>
    

    The output only contains those "staff_member" elements with start dates from 2000 onwards and permanent contracts.

    If you are adding extra inputs to the And 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 false input, it does not check any remaining inputs as the output value must be false. In each case, the Mapper will only reach the final test defined if all preceding inputs have returned true.
    If the And 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

    Set

    Values

    Comparator

    Data Mapping