XML Mapping Editor Tutorial

The XML Mapping Editor is best explained by going through a number of tutorials. Each tutorial will show you how to use the XML Mapping Editor to create mappings between DTDs that have different structures, and generate the resulting XSLT script.

Tutorial 1

Tutorial 2


Tutorial 1 - CD Title

Setup

Before you start this tutorial, make sure you have created a solution and a project. In the following example, we assume the B2B/MyProject container is created.Under Perspective, switch to the XML Perspective. The DTDs for this tutorial is located in plugins\xmlmappingui\samples\cdexample. Use File->Import to import the cdtitle.dtd and the newcdtitle.dtd into the project MyProject.

Getting Started

From the Workbench, choose File New->XML Mapper, the DTD to DTD Mapping wizard will come up. If necessary, specify the appropriate container and rename the default mapping session name to cdmap.xmx.

Turn, to the next page, to specify the source DTD  Use the Add button to add the cdtitle.dtd

Turn to the next page to specify the target DTD. Use the Browse button to add the newcdtitle.dtd.

Turn to the next page. Select CDLib to be the source root element. Select Collections to be the target root element.

When you hit Finish, a cdmap.xmx resource under B2B/MyProject is created, and the XML Mapping Editor is launched as shown below:


Define mappings between the source and target elements

The next step is to map the source elements to the target elements and attributes:
  1. Under the Source, select artist element. Under the target, select the artist attribute. Right mouse button 2 and choose Add Mapping. This indicates the artist element under the source CD is mapped to the artist attribute under the target CD.
  2. Under the Source, select title element. Under the target, select title element. Right mouse button 2 and choose Add Mapping.
  3. Under the Source, select description element. Under the target, select description element. Right mouse button 2 and choose Add Mapping.
This completes all the mapping for this scenario. Notice how the format element from the source is not mapped to any element in the target. The Mapping Summary Table shows all the mappings between the source and the target.


Generating the XSLT Script

Once you have completed the mappings, you can generate the XSLT script by clicking on the Generate a XSLT script toolbar button. The Generate XSLT script wizard will come up. Accept the default newcdtitle.xsl filename and hit Finish. The result XSLT script will be generated and displayed in the editor as shown below.


Testing the XSLT Script

Once you have generated your XSLT script, you can invoke the Xalan processor to do the transformation. You can use the plugins\xmlmappingui\samples\xslt.bat file to invoke the Xalan processor. You will need to set up the environment variable VABASE to point to where you have installed the WebSphere Studio Workbench.

A plugins\xmlmappingui\samples\cdexample\cdtitle.xml file is provided for you to try out your generated XSLT script. Go to the directory plugins\xmlmappingui\samples\cdexample and type:

    ..\xslt -in cdtitle.xml -xsl newcdtitle.xsl > newcdtitle.xml
to get the result newcdtitle.xml file.