Liquid XML Studio
See Also Send Feedback
Data Mapping > Data Mapper Functions > By Category > String > Left

Glossary Item Box

Function Name
Retrieve left-most section of a String to a particular length
String Text String to retrieve left part of
Length Length of result String
Result Text String comprising the left-most characters from the input String, with number of characters specified by Length input
none -


The Data Mapper String Left function retrieves the left-most section of an input String, with the length also specified as input. In other words, the Left function retrieves the first n characters in the input String, creating a substring containing these characters. The Left function is useful if your target data model involves size restrictions, allowing you to limit the length of particular mapped String items. To apply the String Left transform 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 product_source.xsd, an XML Schema Definition inferred from the following source:

Source XML XML Copy Code
  <name>Kitchen Chair</name>
  <description>This lovely chair has lots of fantastic qualities ag65d4hn78</description>
  <name>Table Lamp</name>
  <description>This beautiful lamp is a very special item h76gfr45v2</description>

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

Target XML XML Copy Code
 <item category="Electrical">
  <item_overview>This is a high performance, reliable toaster.</item_overview>
 <item category="Gardening">
  <item_overview>This sturdy but lightweight shovel is great..</item_overview>

The data models produce for a retail service. Here is the Data Mapper with Source and Target imported:

Data Mapper String Left Function

Let's drag the String Left function from the Component Palette into the mapping area:

String Left Component

String Left Transform Added

The String Left function takes two inputs and gives a single output. The String input should be connected to the source text String item to retrieve the result text from. The Length input requires a number input indicating the length of the desired left String section. The Left function output should be connected to the target item, in the XML Writer or another function. First connect the "description" item in the XML Reader to the String input of the Left function:

Reader to Left String Input

Next connect the Left output to the "item_overview" item in the XML Writer:

Left Output to Writer Input

Now we need to specify the length of the desired left String portion. To do this, we need a Constant Value. Drag one from the Data Type section in the Component Palette onto the mapping area:

Constant Value Added

We need to specify the value we want the Constant to have. To do so, right-click it and choose Show Properties. Select one of the integer types from the drop-down Data Type menu and enter your chosen number in the Value field.

Constant Properties

For this example we are limiting the output String to the first 15 characters of the input String. Connect the Constant output to the Left function Length input:

Constant to Left Input

Now when the source item is mapped to the target item the values will be restricted to the 15 left-most characters.

Finally let's make the remaining input and output connections:

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 XML Copy Code
 <item category="Furniture">
  <item_name>Kitchen Chair</item_name>
  <item_overview>This lovely cha</item_overview>
 <item category="Lighting">
  <item_name>Table Lamp</item_name>
  <item_overview>This beautiful </item_overview>

The input element value has been limited to the first 15 characters as part of the mapping process. Often, XML mapping involves converting from legacy systems to new applications in which you may have restrictions in terms of storage space. The Left function can also be useful for other types of String content, for example non-human-readable Strings comprising data items in which you do not need all characters to be preserved when mapping to a new model.

The SubString function is an alternative option if you need to specify the start and length of your required characters within a String.

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

See Also