IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Defining and transforming data > Transforming data > Transforming data using XML maps

Mapping substitutable elements using an XML map

A substitution group is a construct in XML Schema (XSD) that allows a set of elements to be substituted for a head element. An XML instance can contain only one of the elements in the substitution group. You can map the elements of substitution groups in an XML map.

Any top-level element can be defined as the head element of a substitution group. Any other top-level element can then be a member of the substitution group, and can be substituted for the head element. The substitutable elements must either be of the same type as the head element, or they must be derived from the head element by extension or restriction.

Many of the industrial standard schemas contain substitution groups. Below is a simple schema sample with a substitution group, Publication.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://SubstitutionGroups/catalog" 
  xmlns:tns="http://SubstitutionGroups/catalog" elementFormDefault="qualified">

<complexType name="BookType">
  <complexContent>
    <extension base="tns:PublicationType">
      <sequence>
        <element name="isbn" type="string"/>
        <element name="publisher" type="string"/>
      </sequence>
    </extension>
  </complexContent>
</complexType>   

<complexType name="MagazineType">
  <complexContent>
    <restriction base="tns:PublicationType">
      <sequence>
        <element name="title" type="string"/>
        <element name="author" type="string"/>
        <element name="date" type="gYear"/>
      </sequence>
    </restriction>
  </complexContent>
</complexType>

 1  <element abstract="true" name="Publication" type="tns:PublicationType"/>
 2  <element name="Book" substitutionGroup="tns:Publication" type="tns:BookType"/>
 3  <element name="Magazine" substitutionGroup="tns:Publication" type="tns:MagazineType"/>
    
 4  <element name="Catalog">
      <complexType>
          <sequence>
            <element ref="tns:Publication" minOccurs="1"/>
          </sequence>
      </complexType>
    </element>  
</schema>

A corresponding XML instance with the element Catalog as the root can contain either a Publication element, a Book element, or a Magazine element.

<?xml version="1.0" encoding="UTF-8"?>
<tns:Catalog xmlns:tns="http://SubstitutionGroups/catalog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://SubstitutionGroups/catalog foo.xsd ">
  <tns:Book>
    <tns:title>tns:title</tns:title>
    <tns:author>tns:author</tns:author>
    <tns:date>2001</tns:date>
    <tns:isbn>tns:isbn</tns:isbn>
    <tns:publisher>tns:publisher</tns:publisher>
  </tns:Book>
</tns:Catalog>

When there is a head element reference in the content model of a source or target, all of the members of a substitution group are available in the XML map editor. The head element is indicated by the icon

The following image shows the sample schema in the XML map editor:

When working with substitution groups, switch to the Detailed view in the upper right area of the map editor, as shown in the image above. You will then see the substitution group elements under the heading Substitution groups, with the head element at the top of the other elements in the group.

In the above mapping, the result will be as follows:

You can use the head element of the substitution group to define your default mapping.

Transforming data using XML maps