Liquid XML Studio
Variable Function Inputs
See Also Send Feedback
Data Mapping > Variable Function Inputs

Glossary Item Box

With some of the Data Mapper functions, you can add and remove inputs. Functions such as Concat and ConcatAll in the String section as well as the And and Or functions in the Logic section allow for variable inputs. This can provide a level of flexibility within your mapping operations. In this section we will look at adding and removing inputs to these functions.

In general, you can add and remove inputs by clicking an existing input in the Mapper, then choosing Add Above, Add Below or Delete.

Right-Click Menu for Inputs

In some cases the order in which the inputs are listed has an effect on how the component functions, but in some cases it does not, as we will see below.

Concatenation

Let's look first at the Concat / ConcatAll functions. These both concatenate input Strings. In both cases, the function appears by default with two inputs to concatenate, or to concatenate all instances of in the case of ConcatAll. If any of the inputs are connected to empty Strings, the function will simply ignore them, so there's no problem if you are dealing with input values which may or may not be present in your source data. Additionally, you can extend the Concat and ConcatAll functions to concatenate additional inputs by using the Add Above or Add Below options. Should you decide you no longer need an additional input in either function, simply right-click it and choose Delete.

Look at the following XML source data, which conforms to the schema staff_source.xsd:

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>false</permanent>
 </employee>
 <employee>
  <first_name>Lynn</first_name>
  <second_name>Nicolson</second_name>
  <started>1999</started>
  <permanent>false</permanent>
 </employee>
</staff>

This is the target we will be mapping to, staff_variable_target.xsd:

We will use the Concat function to concatenate the first and second names for each staff member. However, we need to include a space character between the names, for which we will need an additional input. Here is the Mapper with source and target imported:

Reader and Writer

Now we drag a Concat component onto the Mapper, connecting the first input to the "first_name" output in the XML Reader.

Concat

Reader to Concat

Now, to define the space character we want to appear between first and second names, we add a Constant Value and right-click to set its properties, choosing a String Data Type and entering a single space as the Value.

Constant

Constant Properties

We connect the Constant output to the second Concat input, so that the space appears immediately following the first name.

Constant to Concat

Since we have now run out of inputs, we need to add another. By right-clicking the second input and choosing Add Below, we ensure that the new input will be concatenated after the two we have already connected.

Add Below

We can now connect the new String 3 input to the "second_name" output in the XML Reader.

Concat Inputs

The result of the Concat function can now be connected to the "name" input in the XML Writer.

Concat to Writer

Finally we make the remaining input and output connections.

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
<human_resources>
 <staffer start_date="2001" is_perm="true">
  <name>Mark Brown</name>
 </staffer>
 <staffer start_date="1998" is_perm="true">
  <name>Jane Jackson</name>
 </staffer>
 <staffer start_date="2008" is_perm="false">
  <name>Joe Simpson</name>
 </staffer>
 <staffer start_date="1999" is_perm="false">
  <name>Lynn Nicolson</name>
 </staffer>
</human_resources>

The output contains the first and second names concatenated with a space between them. If we had needed additional inputs to the Concat function we could simply have added them in the same way. The process is exactly the same for adding new inputs to the ConcatAll function.

Logic

Now let's explore varying the inputs for the Logic functions Or and And. When the Mapper encounters either of these functions, it checks the input values as part of a conditional test. With And, all inputs must equate to true for a true output. With Or, only one input needs to equate to true for a true output. We will be using the buyer_source.xsd Schema, and the following XML data:

Input XML Copy Code
<client_base>
 <buyer>
  <name>Charles Graham</name>
  <ref>12876</ref>
  <total_bought>10599</total_bought>
  <registered>true</registered>
 <since>2003</since>
 </buyer>
 <buyer>
  <name>Amy Henderson</name>
  <ref>14332</ref>
  <total_bought>8900</total_bought>
  <registered>false</registered>
  <since>2005</since>
 </buyer>
 <buyer>
  <name>David Wright</name>
  <ref>10998</ref>
  <total_bought>13500</total_bought>
  <registered>true</registered>
  <since>2001</since>
 </buyer>
</client_base>

Our target Schema is buyer_target.xsd:

Assume that we are mapping the data as part of a targeted marketing campaign. We only want to map buyers with particular sets of input data values. To begin with, we will use the And function to map only those buyers who meet three conditions. Here is the Mapper with Source and Target imported:

Reader and Writer

We only want to map buyers whose total purchases to date amount to at least £10000, so we drag a Greater Than or Equal component out, connecting its Value 1 input to the "total_bought" output in the XML Reader.

Greater Than Or Equal

Reader to Greater Than or Equal

We use a Constant Value to define the figure of 10000 as an integer.

Constant

Constant Properties

Connect the Constant output to the Greater Than or Equal Value 2 input.

Constant to Greater Than or Equal

We also want mapped buyers to have only been customers since after 2002, so we drag a Greater Than function over. We use a Constant to define the value of 2002, connecting it to the second input of the Greater Than function, with the first input connected to the "since" output in the XML Reader.

Greater Than

Constant

Greater Than Added

Now we can add the And function, connecting its inputs to the outputs of the Greater Than and Greater Than or Equal functions. However, we also want to include the buyer's registered status as part of the conditional test, so we need to add a new input by right-clicking one of the And inputs and choosing Add Below or Add Above.

And

Add Inputs

Now we can connect the new input to the "registered" output in the XML Reader, since it contains a boolean value.

Reader to And

Since we are using this data to determine whether values are mapped or not, we now add a Filter function to the Mapper, connecting its Nodes input to the "buyer" output in the XML Reader and its Bool input to the output of the And function. The Filter output connects to the "client" input in the XML Writer.

Filter

Filter to Writer

This will ensure that a "buyer" element will only be mapped if its content passes the conditional tests defined as inputs to the And function. We can now make the remaining input and output connections to complete the mapping definition.

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
<target_clients>
 <client name="Charles Graham">
  <client_num>12876</client_num>
 </client>
</target_clients>

The "buyer" elements have only been mapped if their content met all three conditions, which in this case means only one is mapped. We can carry out the same process using the Or function if we want the buyers to be mapped if they meet any one of the conditions, simply by changing the And component to Or and adding inputs using the same process.

Or

Inputs and Outputs Connected

The output in this case is as follows:

Output XML Copy Code
<target_clients>
 <client name="Charles Graham">
  <client_num>12876</client_num>
 </client>
 <client name="Amy Henderson">
  <client_num>14332</client_num>
 </client>
 <client name="David Wright">
  <client_num>10998</client_num>
 </client>
</target_clients>

Here all three "buyer" elements in the source have been mapped as each of them met at least one of the three specified conditions. In the above examples we have carried out three tests for each function, but we could add more if necessary, by following the same steps repeatedly until we achieve the set of chained conditionals that will result in the desired mapping output.

In some cases the order in which you list your inputs may affect what happens when the Mapper executes. With the Concat and ConcatAll functions, the concatenation result reflects the order of inputs, as in the above example where we needed the first name, space, second name order to be observed. With the Logic functions, although the output may not be affected by the order of inputs, the function of the Mapper itself will be determined by it.

For example, with the And function, as soon as the Mapper encounters a false input, it returns false without checking any of the remaining inputs, as the output must be false. Similarly, with the Or function, when the Mapper encounters a true input, it outputs true straight away, as only one input must be true for the output to be true. You can therefore plan your tests for efficiency if you know something about the input data that may affect the number of tests that may need to be carried out in each case. Naturally this is only a consideration for complex tests.

See Also

String
Concat

Logic
And
Or