Altova MapForce 2024 Enterprise Edition

One Source to One Target

Home Prev Top Next

This tutorial describes how to create a mapping for one of the most basic scenarios. Our goal is to transfer data from XML file A (with XML schema A assigned to it) to XML file B (with XML schema B assigned to it). The broad outline of our method will be as follows:

 

1.Since we are using two data structures, we will create two components (Source and Target) in our mapping design.

2.To transform one document into another, we will select a suitable transformation language.

3.Then we will need to connect source nodes to the desired target nodes. It is these connections that constitute the mapping and determine what source node maps to what target node.

4.As a result of the mapping, we will get the target XML document that is valid in accordance with the target schema.

5.Finally, we can save the output XML file.

 

For more information about how data transformation is carried out, see the abstract model below.

 

Abstract model

The abstract model below illustrates the data transformation in this tutorial:

MF_Tut1_SchemaToSchema

Our mapping has one source and one target. The source schema (Books.xsd) describes the structure of the source instance file (Books.xml). The target schema (Library.xsd) describes the structure of the target instance file (BooksOutput.xml). When you connect the nodes of the source to the corresponding nodes of the target, the mapping generates transformation code in XSLT 3.0. The transformation code reads data from Books.xml and writes this data to BooksOutput.xml.

 

Source and target files

The code listing below shows sample data from Books.xml that will be used as a data source.

 

<books>
  <book id="1">
     <author>Mark Twain</author>
     <title>The Adventures of Tom Sawyer</title>
     <category>Fiction</category>
     <year>1876</year>
  </book>
  <book id="2">
     <author>Franz Kafka</author>
     <title>The Metamorphosis</title>
     <category>Fiction</category>
     <year>1912</year>
  </book>  
</books>

 

This is how we want our data to look in the target file called BooksOutput.xml:

 

<library>
  <last_updated>2015-06-02T16:26:55+02:00</last_updated>
  <publication>
     <id>1</id>
     <author>Mark Twain</author>
     <title>The Adventures of Tom Sawyer</title>
     <genre>Fiction</genre>
     <publish_year>1876</publish_year>
  </publication>
  <publication>
     <id>2</id>
     <author>Franz Kafka</author>
     <title>The Metamorphosis</title>
     <genre>Fiction</genre>
     <publish_year>1912</publish_year>
  </publication>
</library>

 

Our goal is to populate the elements <author>, <title>, <genre> and <publish_year> of the target file with the content of the equivalent elements in the source file (<author>, <title>, <category>, <year>). The attribute id in the source file will be mapped to the <id> element in the target file. Finally, we will populate the <last_updated> element of the target file with the date and time indicating when the file was last updated.

 

To carry out the required data transformation, take the steps described in the subsections below.

 

© 2017-2023 Altova GmbH