Translating data in a message
You can translate data from one form to another.
About this task
A typical example of the requirement to translate data is if the items are known in one message by names, and in another message by numbers. For example:
Type Name Type Code
Confectionary 2000
Newspapers 3000
Hardware 4000
Consider the following input message:
<Data>
<Items>
<Item>
<Cat>1000</Cat>
<Description>Milk Chocolate Bar</Description>
<Type>Confectionary</Type>
</Item>
<Item>
<Cat>1001</Cat>
<Description>Daily Newspaper</Description>
<Type>NewsPapers</Type>
</Item>
<Item>
<Cat>1002</Cat>
<Description>Kitchen Sink</Description>
<Type>Hardware</Type>
</Item>
</Items>
<TranslateTable>
<Translate>
<Name>Confectionary</Name>
<Number>2000</Number>
</Translate>
<Translate>
<Name>NewsPapers</Name>
<Number>3000</Number>
</Translate>
<Translate>
<Name>Hardware</Name>
<Number>4000</Number>
</Translate>
</TranslateTable>
</Data>
This message has two sections; the first section is a list of items in which each item has a catalog number and a type; the second section is a table for translating between descriptive type names and numeric type codes. Include a Compute node with the following transform:
SET OutputRoot.XMLNS.Result.Items.Item[] =
(SELECT M.Cat, M.Description, T.Number As Type
FROM
InputRoot.XMLNS.Data.Items.Item[] As M,
InputRoot.XMLNS.Data.TranslateTable.Translate[] As T
WHERE M.Type = T.Name
);
The following output message is generated:
<Result>
<Items>
<Item>
<Cat>1000</Cat>
<Description>Milk Chocolate Bar</Description>
<Type>2000</Type>
</Item>
<Item>
<Cat>1001</Cat>
<Description>Daily Newspaper</Description>
<Type>3000</Type>
</Item>
<Item>
<Cat>1002</Cat>
<Description>Kitchen Sink</Description>
<Type>4000</Type>
</Item>
</Items>
</Result>
In the result, each type name has been converted to its corresponding code. In this example, both the data and the translate table were in the same message tree, although this is not a requirement. For example, the translate table could be coded in a database, or might have been set up in LocalEnvironment by a previous Compute node.