Liquid XML Studio 2019
Data Mapping > Data Mapper Functions > By Category > String > TrimStart

Function Name
Trim Start
Trim Start
Trim leading whitespace from the start of an input String
String Text String to trim leading whitespace from
Result Text String trimmed with whitespace characters removed from the start
none -


The Data Mapper String Trim Start function returns an input String with any whitespace characters removed from the start. Since much XML data comes from unpredictable sources such as user input with a system, it is often necessary to trim whitespace characters during mapping, ensuring that the mapped data is ready for use and does not waste any unnecessary storage space. To apply the String Trim Start 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 review_source.xsd, an XML Schema Definition inferred from the following source:

Source XML
Copy Code

      I thought this was a really excellent product.

   I really hate this product.


We are intentionally including additional whitespace characters around the content for demonstration. For our target schema we will be using review_target.xsd, inferred from the following XML:

Target XML
Copy Code
 <review_item product="456">
  This is a wonderful item.
 <review_item product="567">
  This item has good points and bad points.

The data models feedback reviews for products. Here is the Data Mapper with Source and Target imported:

Data Mapper String Trim Start Function

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

String Trim Start Component

String Trim Start Transform Added

The String Trim Start function takes one input and gives one output. The String input should be connected to the source text String item to trim leading whitespace characters from. The String Trim Start function output should be connected to the target item in the XML Writer or another component. First connect the "content" item in the XML Reader to the String input of the Trim Start function:

Reader to Trim Start String Input

Next connect the Trim Start output to the Element Value item in the XML Reader:

Trim Start Output to Writer Input

Notice that we are mapping an element in the source XML to an element value in the target XML. The Mapper maps freely between elements, attributes and values.

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
Copy Code
    <review_item product="123">I thought this was a really excellent product.  
    <review_item product="234">I really hate this product.

The input element value has been mapped without the leading whitespace we had on the left in the XML source within the element content. Notice that the whitespace from the end of the input String has been preserved, with whitespace only removed from the left side. If you need whitespace trimmed from the right, use the Trim End function or the Trim function if you need it trimmed from both ends.

When text Strings come from varied sources such as text files and other data stores, it is common to end up with whitespace characters such as new lines, carriage returns and spaces being appended at one or both ends. For this reason the Trim functions can save considerable time spent carrying out manual alterations. Trimming your Strings means that your mapped text is immediately ready for user display and other uses.

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

See Also

Data Mapping