Mapping and Transforming Data : Shortcuts

Shortcuts
The Move In, Insert, Add Child, and Edit Statement buttons on the toolbar are ways to manually manipulate XSLT statements in the Function panel. These buttons, however, only add or modify one statement at a time. Also, there are some situations where you wish to convert a hint into a statement without performing any mapping. This section describes shortcuts for manipulating XSLT statements.
Statement Menu Options
When you select an element in the function input schema and right-click, a menu appears. The Statement menu item contains several sub-items that are useful shortcuts for creating XSLT statements.
Surround with Choice — a shortcut for adding a choice statement and its associated conditions or otherwise statements around the currently selected element.
Surround with If — a shortcut for adding an if statement and placing the currently selected element as the sub-element of the if.
Surround with For-Each-Group — a shortcut for moving the current element into a For-Each-Group statement and adding a Group-By grouping statement.
Duplicate — a shortcut for creating a duplicate of the currently selected element (including any mappings or XPath formulas for the element). The duplicate is added below the currently selected element.
Insert Model Group Content — a shortcut for inserting the contents of a selected model group into the mapper tree. The selected element in the function input schema is replaced by the contents of the model group you select.
Dragging to the Left
Dragging an element in the function input schema to the left past the divider between the two areas of the Input tab changes a hint into an XSLT statement. Figure 5 illustrates dragging an element to the left.
Figure 5 Dragging to the left to change a hint to a statement
This shortcut is useful in the following situations:
When you have a choice element, dragging to the left brings up the Mapping Wizard and allows you to choose a type for the element.
When you have an element of type Any, dragging to the left brings up a dialog that allows you to specify the type for the element.
Cutting and Pasting
The Function panel is an XSLT template for specifying the function’s input schema. You can choose any element in the Function panel and select Copy from the right-click menu or press the Control-C keys to copy the XSLT statement for the element. Once the XSLT is copied, you can paste it into a text editing tool to view or modify the code.
You can also paste arbitrary XSLT code into the Function panel using the right-click menu or the Control-V keys. Pasting XSLT code from the copy buffer places the code above the currently selected element in the Function panel.
Automatic Testing (at Runtime)
When you map Scope Variables elements to Function elements, the behavior of the mapping depends upon the types of elements you are mapping. In the simplest case of mapping a required element in the Scope Variables schema to a required Function element, the value of the Scope Variables element is assigned to the required Function element.
However, when elements are optional or nillable, more complex tests are necessary. When you drag the Scope Variables element to the Function element, the necessary tests are automatically placed into the Function XSLT template.
This section describes the result of mapping different types of elements. The types of mappings are described, then an example is given that illustrates these mappings and shows the XSLT code that is generated automatically when these mappings are performed at runtime.
Required to Required
Specifies that the statement should always include the required Function element and its value should be obtained from the required Scope Variables element that the element is mapped to.
Optional to Optional
Specifies that the statement should test if the Scope Variables element is present, and if so, include the optional element in the function’s input. If the Scope Variables element is not present, the optional element is omitted from the function’s input.
Nillable to Nillable
Specifies that both the Scope Variables and Function elements can be nil. Therefore, the value of the Function element is set to the value of the Scope Variables element. The value of the Function element is set explicitly to nil if that is the value of the Scope Variables element.
Optional to Nillable
Specifies that the statement should test if the optional Scope Variables element exists. If the element exists, the Function element should be created and set to the value of the Scope Variables element. If the Scope Variables element does not exist, the element is omitted from the function input schema.
Nillable to Optional
Specifies that the statement should test if the Scope Variables element has a value specified, and if so, the optional element in the Function panel should be set to the value of the Scope Variables element. Otherwise, if the Scope Variables element is nil, the optional element is omitted from the Function panel.
Optional & Nillable to Optional & Nillable
Specifies that if the optional Scope Variables element exists, then include the optional Function element in the input schema. If the Scope Variables element is nil, set the value of the Function element explicitly to nil. If the Scope Variables element is not nil, set the value of the Function element to the value of the Scope Variables element. If the Scope Variables element is not present, then omit the optional element from the function input schema.