Liquid XML Studio
See Also Send Feedback
Data Mapping > Data Mapper Functions > By Category > Values > Constant

Glossary Item Box

Function Name
Constant Value
Data Type
Defines a Constant data value
None -
Value The data value defined within the Constant
Name String name to display within the Mapper
Data Type Data type for the Constant Value
Value The value represented by the Constant


The Data Type Constant Value component defines a single data value for use within mapping functions. When you carry out transformations on your data, it is common to input data values such as characters, Strings and numbers. The Constant Value component allows you to do this. You can define many different types of Constant Value and typically the component is used in conjunction with other mapping functions. Although the Constant component is simple to use, we will look at a relatively complex example here, using two constants, one of type String and the other numerical. The process is as follows:

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

Source XML Copy Code
  <title>Journal of Medical Science</title>
  <title>Advancements in Linguistics</title>

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

Target XML Copy Code
 <volume name="Journal of Physiology">
 <volume name="Philosophy Today">

The data models library journals. If you look at the target XML, you will see that the "sections" element contains a series of characters, followed by an underscore character and a number. We are going to build this String by concatenating all "section" elements within a given parent, then concatenating this with an underscore character and an integer representing the number of sections in the parent element plus one. We will use Constants to represent the underscore String and the number 1, to add to the number of sections. Here is the Data Mapper with Source and Target imported:

Data Mapper Source and Target

Drag two Constant Values from the Component Palette onto the mapping area:

Constant Component

We need to set the properties for each, by right-clicking, then choosing Show Properties. For the first one, enter "underscore" as the Name, select String from the Data Type drop-down list and enter a single underscore character ("_") as the Value. Altering the name will make the Constants easier to work with in the Mapper.

Constant Properties

For the second Constant, enter "one" as the Name, choose an integer type from the Data Type drop-down list and enter "1" as the Value.

Constant Properties

Now you can see which Constant is which in the Mapper.

Constants Added

Since we want to concatenate the "section" items with an underscore and their total number plus one, let's drag a Count function from the Aggregate section of the Component Palette. Connect its Context input to the "journal" output of the XML Reader, since we want the number of "sections" per "journal". Connect the Value input of the Count function to the "section" output of the XML Reader, since this is the element we want to count.

Reader to Count

Now we have the number of items, but we also need to add a value of 1 to it. Drag an Add function from the Maths section, connecting its first Value input to the Count output and its second Value input to the output of the "one" Constant we created.

Constant Addition

Now we need to concatenate all "section" items within each parent, so drag a ConcatAll function onto the Mapper. Connect the "section" item to the first String input of the ConcatAll function. We do not need to supply a second input to the function in this case - you can remove the second input from display if you prefer, by right-clicking it and choosing Delete, although it will still function if you leave it intact.

ConcatAll Function

Now we need to concatenate the combined "section" items with the underscore and number. Start by dragging a Concat function onto the Mapper. Connect its first String input to the output of the ConcatAll function, with its second String input connected to the "underscore" Constant we created.

Concat Function

Now we can combine the concatenated "section" items plus underscore character with the number we have arrived at. Drag another Concat function over, connecting its first String input to the output of the previous Concat, and its second input to the output of the Add function.

Concat Function

Now we can connect the output from this second Concat function to the "sections" input in the XML Writer.

Data Type Constant Reader to Writer

Finally, connect the remaining inputs and outputs, with the "journal" and "section" items both connecting to two different inputs:

Input and Output Connections Mapped

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
 <volume name="Journal of Medical Science">
 <volume name="Advancements in Linguistics">

The "sections" element now contains the combined elements together with an underscore and count value plus one. In practice, you can use the Constant Value function in many different ways. As well as allowing you to insert specific items of data into your mapping projects, it lets you perform calculations on your data.

Possible data types for Constant Values include: Binary, Boolean, Byte, DateTime, DateTimeOffset, Decimal, Double, Float, Guid, Int16, Int32, Int64, SByte, String, Time and Node.

See Also