Function Name |
Left | ||||
Category |
String | ||||
Icon |
|||||
Description |
Retrieve left-most section of a String to a particular length | ||||
Inputs |
|
||||
Outputs |
|
||||
Properties |
|
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 |
---|---|
<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 XML | Copy Code |
---|---|
<goods> <item category="Electrical"> <item_name>Toaster</item_name> <item_overview>This is a high performance, reliable toaster.</item_overview> </item> <item category="Gardening"> <item_name>Shovel</item_name> <item_overview>This sturdy but lightweight shovel is great..</item_overview> </item> </goods> |
The data models produce for a retail service. Here is the Data Mapper with Source and Target imported:
Let's drag the String Left function from the Component Palette into the mapping area:
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:
Next connect the Left output to the "item_overview" item in the XML Writer:
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:
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.
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:
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:
We can now execute the transform by pressing Shift-F5 or the Execute button (). The transform is applied and the file we selected as output opens in the editor:
Output XML XML | Copy Code |
---|---|
<goods> <item category="Furniture"> <item_name>Kitchen Chair</item_name> <item_overview>This lovely cha</item_overview> </item> <item category="Lighting"> <item_name>Table Lamp</item_name> <item_overview>This beautiful </item_overview> </item> </goods> |
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.