WebSphere Message Brokers
File: ak05790_
Writer: Bill Oppenheimer

Task topic

This build: July 31, 2007 21:32:30

Translating data in an XML message

You often need to translate data from one form to another. For example, in one message the types of items are known by names and in another message the items are known 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 is a list of items in which each item has a catalogue number and a type; the second is a translate table between descriptive type names and numeric type codes. If you include a Compute node with the following transform:

SET OutputRoot.XML.Result.Items.Item[] = 
   (SELECT M.Cat, M.Description, T.Number As Type
     FROM 
       InputRoot.XML.Data.Items.Item[]               As M,
       InputRoot.XML.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.

Related concepts
Message flows overview
ESQL overview
Message modeling
Related tasks
Designing a message flow
Defining message flow content
Managing ESQL files
Related reference
Compute node
Database node
Filter node
ESQL reference
SELECT function
SET statement
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:32:30

ak05790_ This topic's URL is: