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

Glossary Item Box

Function Name
Right
Category
String
Icon
Right
Description
Retrieve right-most section of a String to a particular length
Inputs
String Text String to retrieve right part of
Length Length of result String
Outputs
Result Text String comprising the right-most characters from the input String, with number of characters specified by Length input
Properties
none -

Usage

The Data Mapper String Right function retrieves the right-most section of an input String, with the length also specified as input. In other words, the Right function retrieves the last n characters in the input String, creating a substring containing these characters. The Right 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 Right 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 Copy Code
<catalogue>
 <product>
  <name>Kitchen Chair</name>
  <category>Furniture</category>
  <description>This lovely chair has lots of fantastic qualities ag65d4hn78</description>
 </product>
 <product>
  <name>Table Lamp</name>
  <category>Lighting</category>
  <description>This beautiful lamp is a very special item h76gfr45v2</description>
 </product>
</catalogue>

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

Target XML Copy Code
<goods>
 <item category="Electrical">
  <item_name>Toaster</item_name>
  <item_overview>jkg7jh543d</item_overview>
 </item>
 <item category="Gardening">
  <item_name>Shovel</item_name>
  <item_overview>nj87hg10kj</item_overview>
 </item>
</goods>

The data models produce for a retail service. For demonstration, let's assume that the "description" item in the input contains a code as its final 10 characters - this code is all we want to map to the output Schema, perhaps to use it as a reference within this or another data source. Here is the Data Mapper with Source and Target imported:

Data Mapper String Right Function

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

String Right Component

String Right Transform Added

The String Right 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 right String section. The Right function output should be connected to the target item in the XML Writer or another component. First connect the "description" item in the XML Reader to the String input of the Right function:

Reader to Right String Input

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

Right Output to Writer Input

Now we need to specify the length of the desired right 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 last 10 characters of the input String. Connect the Constant output to the Right function Length input:

Constant to Right Input

Now when the source item is mapped to the target item the values will be restricted to the 10 right-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 Copy Code
<goods>
 <item category="Furniture">
  <item_name>Kitchen Chair</item_name>
  <item_overview>ag65d4hn78</item_overview>
 </item>
 <item category="Lighting">
  <item_name>Table Lamp</item_name>
  <item_overview>h76gfr45v2</item_overview>
 </item>
</goods>

The input element value has been limited to the last 10 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 Right function can therefore be useful for both human-readable and non-human-readable Strings comprising data items in which you do not need all characters to be preserved when mapping to a new model.

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

See Also