When you need to map a source element to a target element with multiple cardinality (0...n) in the XML mapping editor, you can use the simple Create Mapping function for a simple mapping, or the XSL choose capability for a more complex mapping. This section uses examples to show you how to use both functions.
Consider this example: a complex type customerOrder may contain a deliveryDates element with attribute "maxOccurs=2". This means that the customerOrder can have a list of at most two delivery dates.
<xsd:element maxOccurs="2" minOccurs="0" name="deliveryDates" type="xsd:dateTime"/>
In the XML mapping editor, the deliveryDates element looks like this:
If you are mapping
from a source element with multiple cardinality to a target element with multiple
cardinality, you may be able to use a simple Create Mapping function
in certain cases. For example, if the maxOccurs of the target element is large
enough to contain the source elements. In the following image in the XML Mapping
editor, the mapping between the source items element and the target items
element is achieved using the Create Mapping function.
If you want to map a source element to a specific instance of a target element with multiple cardinality, a simple Create Mapping function is not sufficient, and you need to use XSL choose. In the remainder of this topic, we use an example to illustrate how to use XSL Choose to map multiple cardinality elements.
Source | Source type | Target | Target type |
---|---|---|---|
id | int | id | int |
billingAddress[1].addressLine1 | string | billingAddr [1] | string |
billingAddress[1]addressLine2 | string | billingAddr [2] | string |
ItemID [x] | int | items[x] -> ID | int |
ItemQuantities [x] | int | items[x] -> quantity | int |
availableDeliveryDates [1] | dateTime | deliveryDates [1] | dateTime |
availableDeliveryDates [2] | dateTime | deliveryDates [2] | dateTime |
shippingAddress1 | string | shipToAddress [1] | string |
shippingAddress2 | string | shipToAddress [2] | string |
salesReps[1] | int | reps[1] | int |
supportReps[1] | int | reps[2] | int |
... <sourceOperation> <order> <id>049728</id> <billingAddress> <addressLine1>221B Baker Street</addressLine1> <addressLine2>London, UK</addressLine2> </billingAddress> <itemID>CAP001</itemID> <itemID>PIPE002</itemID> <itemQuanities>1</itemQuanities> <itemQuanities>2</itemQuanities> <availableDeliveryDates>2001-12-31T12:00:00</availableDeliveryDates> <availableDeliveryDates>2002-12-31T12:00:00</availableDeliveryDates> <shippingAddress1>63, Aston Road North</shippingAddress1> <shippingAddress2>Birmingham</shippingAddress2> <shippingAddress2>UK</shippingAddress2> <salesReps>1</salesReps> <salesReps>2</salesReps> <supportReps>3</supportReps> <supportReps>4</supportReps> <type>1</type> </order> </sourceOperation> ...
... <targetOperation> <customerOrder> <shipToAddress>63, Aston Road North</shipToAddress> <shipToAddress>Birmingham</shipToAddress> <deliveryDates>2001-12-31T12:00:00</deliveryDates> <deliveryDates>2002-12-31T12:00:00</deliveryDates> <billingAddr>221B Baker Street</billingAddr> <billingAddr>London, UK</billingAddr> <reps>1</reps> <reps>3</reps> <id>049728</id> <items> <ID>CAP001</ID> <quantity>1</quantity> <ID>PIPE002</ID> <quantity>2</quantity> </items> </customerOrder> </targetOperation> ...