Mapping nodes
You can map nodes that consist of elements or attributes from the source file to nodes in the target file.
The following mapping combinations are accepted:
- an attribute to an attribute
- an attribute to an element
- an element to an element
- an element to an attribute
- many nodes to one node
The following instructions were written for the Resource perspective, but they will also work in many other perspectives.
To create a mapping, follow these steps:
- Open your XML to XML mapping in the XML to XML mapping editor.
- Select one or more elements or attributes in the source file. Use the Ctrl key to select more than one element or attribute in the source.
- Select an element or attribute in the target.
- Right-click and select Create Mapping.
Mapping options
The Match Mapping command is used to map nodes with common names. To use this option:
- Open your XML to XML mapping in the XML to XML mapping editor.
- Select one or more nodes to be mapped. They do not have to have a common name.
- Select Mapping > Match Mapping. The tool will map the selected nodes, then it will attempt to map the children of the selected source nodes to the children of the selected target nodes based on common names. The children of the newly-mapped child nodes with common names are then mapped. The process continues until all of the descendant nodes with common names are mapped.
To remove a mapping, right-click the mapped element or attribute and select Remove Mapping.
Selecting options
Choice support enables you to dynamically select or map different members of a choice during a mapping session. To create a mapping using a choice member not currently shown in the Target or Source view,...
- Open your XML to XML mapping in the XML to XML mapping editor.
- Select the choice member that is currently shown in the Source or Target view. An arrow will appear next to it. Click the arrow and select the appropriate member from the drop down menu.
- Create the mapping.
Note that the Overview view always reflects the mappings in the current Target view. Therefore if the target contains a choice, only the member currently showing in the Target view will appear in the Overview view. The other members of the choice, even though they may be mapped, will not appear in the Overview view. However, all mappings appear in the Outline view regardless of the current Target view.
For example,
- You select as your source file, Address.dtd, which contains a choice with two members: Province and State.
- You select Person.dtd as your target file, which also contains a choice with the two members: Province and State.
- When you open your mapping session, Province is displayed in both the Source and Target view. You create a mapping between the two Province members.
- You then click Province in the Source view and select State from the drop down menu and do the same in the Target view. You can now create a mapping between those two members.
Mapping to elements with empty content
Mapping to an XML element that has no content at all (for example, <Person/>) is different than mapping to an XML element that contains character data (for example, <Person>Molly</Person>). In the latter case, the mapping signifies that the data from the source node will be used as the character data for the target element. However, in the former case, the mapping is equivalent to nothing happening since the target element can never have any content. In other words, the mapping has no effect on the XSLT that is generated.
In a DTD, an element that has no content at all is specified using the keyword 'EMPTY' (for example, <!ELEMENT Person EMPTY>). In an XML schema, it is not as straight forward. One of the syntatically compact ways of specifying an empty content element in an XML schema is to define a complex type without any simple content or complex content (for example, <xsd:element name="Person"> <xsd:complexType/></xsd:element>). This can be interpreted as shorthand for complex content that restricts anyType.
Parent topic
Editing an XML to XML mapping
Related concepts
XML to XML mapping editor
Related tasks
Specifying source and target files
Sorting elements