Tutorial & Interface
Creating a Simple Mapping
In this tutorial, we’ll cover using the Data Mapper to create XSLT to map between one format of XML and another. This tutorial expands on the concepts covered in “Using Transformers,” so users are expected to be familiar with that material.
This interface and related tutorials demonstrate the use of the Data Mapper in Route configurations to transform between XML Formats. In this particular exercise, an existing Route (from “Training – Creating a Simple Route”) is modified to transform a “PeopleA” XML format to a “PeopleB” XML format.
- Directory / File Listener
- Directory / File Transport
- eiConsole Testing Mode
- XSLT Transformer
- Data Mapper
- Format Readers
- XML Format Reader
How to Use This Example
Click the links below for the files you will need for this tutorial, then DOWNLOAD INTERFACE to get started. (Once logged into the eiConsole it immediately shows up in your “PIE” inbox for use.)
If you are not logged in to the eiConsole, you will be prompted to login before the interface downloads into your eiConsole “PIE” inbox.If you have not downloaded and installed a FREE eiConsole 90-Day Trial you will have the opportunity to register via a simple process after you click DOWNLOAD INTERFACE. Once you are logged in the interface will automatically download into your “PIE” inbox.
Next, use the tutorial and walk through it step-by-step. You may check your work against the Route (Sample Data) provided above.
Creating a new Route and configuring a Directory/File Listener / Transport pair.
You can configure XSLT at either the Source or Target Transform. The reasons for choosing one or the other are usually due to topographical concerns. For this tutorial, it does not matter which we use, so we’ll just arbitrarily choose the Target Transform.
You now have a variety of options available to you. You can type in the name of an existing XSLT file, browse to one, edit a selected one, specify if you wish to cache the XSLT, enable 2.0 support, and even select which XSLT engine to use. Using the defaults for these options is more than sufficient for most transformations regardless of complexity.
Editing a new Mapping
As we have no existing XSLT document to edit, simply clicking the New button with no document selected will open the Data Mapper to edit a new mapping:
Loading in the Source and Target formats
Next, we’ll need to add our sample file. Click Add and browse to PeopleA.xml, which should have been provided with this tutorial:
Reading our Target format
Click Read Format, select Yes, and then review the Target format panel:
For this mapping, there’s not a significant difference between the two formats except for one detail: the Source format has a “People” root element, and the “Person” elements underneath it repeat. Our Target has only the one Person. We’ll simply be directly mapping the first Person in the Source to the only Person in the Target.
Constructing the Mapping
The first thing to do in constructing the mapping itself is to provide a “template” match. This is some element from the Source which we’ll match against and take some set of actions against. Select the “People” element from the Source and drag-and-drop it onto the “stylesheet” element in the center:
Creating a Person from the Target
In XSLT, this is creating an instruction called a “template” with an attribute called “match” containing the XPath expression for the People element in the Source. It effectively means, “when I encounter some People element, run these instructions.” The action we want to take is to create a Person from the Target; effectively, we want to say, “When I encounter some People element, I want to create a single Person element.” To do this, drag “Person” from the Target format onto “People” in the center:
The center mapping should look exactly like this:
Continue this for each of the values. Note that you will not drag “Name” onto the center “Name” – only it’s child elements (so “First” onto “First”). When you’re finished, it should look something like this:
We have two other sections to investigate now. First, click the XSLT View tab at the bottom of the screen:
Making changes directly to the XSLT view
You can make changes directly to the XSLT view and they will show up in the Mapping (GUI) view. This particular editor features auto-completion, auto-formatting, and a few other useful features for doing manual editing. Next, click the “Testing” tab:
This is made up of three panels. The first is the Source sample which, if you used the XML Format Builder, should already have our “PeopleA.xml” file loaded for testing. The second panel is the “Results” panel, which shows the results of the transformation. Finally, the “Output” panel shows any messages from the XSLT engine, such as errors or warnings.
Executing the Transformation
We’ve now completed our basic mapping. Save the mapping using the “Save” button or menu item (we’ll name ours “Simple Mapping”) and close the Data Mapper to return to the eiConsole.
Reviewing the before and after
As you can see, performing mappings is simply a matter of dragging and dropping between the Source and Target formats. Use the “Using Iteration” tutorial, to review the complexity and functionality a bit through iteration.