Local variables are used for mapping source elements, mapping functions or constants to a specific target element. They are declared and used only for the specific target element or attribute for which they are declared.
To use a local variable in a mapping activity, you need to map it to the specific target element or attribute. This will successfully execute the local variable when you execute the specific mapping activity in the process flow.
Declare Local Variable
Steps to declare a Local Variable
- Ensure that the source and target schemas are loaded and all their elements are listed under their respective nodes.
- Click Node tab displayed in the Mapping Graph Area. All tabs of the Node tab are displayed.
Click the Local Variables tab. The Local Variable pane is displayed in the Mapping Graph Area (see Figure 527).
Figure 527: Local Variable Pane
- Click Local Variable Name text field and enter the name of the local variable you want to create (e.g. varQuery). Press the Tab or Enter key. This takes the control to the Local Variable Value field.
- Enter the value of the local variable in the Local Variable Value field. You can enter the value of the local variable using one of the listed methods:
- Click required source element
- Select the required Mapping function
- Type the required value manually
- Select a Custom Method
Enter comments for the local variable in the Add Comment field (see Figure 528). For example, if the local variable value contains complex XSLT logic, you can enter its description in this field.
The Comments field is resizable.
Figure 528: Enter Name, Value and Comment for Local VariableTo select a Custom Method as the value of a local variable, double click the desired Custom Method under Custom Methods in the Parameters Panel. The selected Custom Method is displayed in the Variable Definition field.
To learn how to declare a Custom Method, refer to section Using Custom Method.
Click the Save Local Variable (
) button to save the local variable for the selected target element. This local variable is added to the list of existing variables in the Local Variable Name field. It is also displayed under Local Variables in the Parameters Panel. If you shift the focus to another node, or click any of the Mapping Rules, Textual Rules, Global Variables, Properties, XSL or Debugger tabs, without saving the local variable, an alert message is displayed (refer to alertmsg Figure 522). The comments added for the local variable are saved and displayed above the local variable declaration in the Mapping XSL (refer to Figure 523).The alert message is also displayed when shifting focus between Global and Node tabs.
Click No to save the local variable and shift the focus to the other object. If you click Yes, then the defined local variable is cleared and the focus is shifted to the other object.
- Once the local variable is saved, it is categorized as Current Variable or Ancestor Variable in the Parameters Panel. If it is created for a child node, then it is saved as a Current Variable. If it is created for a parent’s parent node, then it is saved as an Ancestor Variable.
- You can rearrange the local variables by dragging it up or down in the list.
Steps to manage a Local Variable from the Parameters Panel
- Right-click the local variable that you want to edit or delete. This displays the right dropdown menu.
Select Edit to edit the variable. This displays the selected local variable in Edit mode. You can edit the value of the local variable in the Local Variable Value field. You can also edit the name of the local variable in the Local VariableName field (see Figure 529).
Figure 529: Edit Name, Value and Comment for Local Variable
Click the Save Local Variable (
) button to save the edited local variable. An alert message is displayed.Figure 530: Alert Message
Click OK to save the changes.
To remove a local variable, select the local variable and click Remove selected local variable (
) button.To remove all local variables, click Remove all local variables (
) button.Alternately, you can delete a local variable from the Parameters Panel itself. For details, refer to the Managing a Global Variable from Parameter Panel section.
Map Local Variable to Target Element
Once you have created a local variable, you can map it to the specific target element or attribute.Steps to map Local Variable to specific target element
- Ensure that the source and target schemas are loaded and all their elements are listed under their respective nodes.
- Click the Node tab displayed in the Mapping Graph Area. All tabs of the Node tab are displayed. Click Mapping Rules tab.
- Select a target element. This displays the selected target element node in the Mapping Graph Area.
Double-click the required local variable under Local Variables in the Parameters Panel. The selected local variable node is displayed in the Mapping Graph Area (see Figure 531).
Figure 531: Add Local Variable Node
- Create a link from the output of the local variable to the input of the target element.
- Click the Apply Mapping ( ) button. This maps the local variable to the selected target element. If you shift the focus to another target element, or click any of the Global, XSL or Debugger tabs, without applying the mapping, then an alert message is displayed (refer to Figure 522).
Click No to apply the mapping and then shift focus to the other object. If you click Yes, then the mapping activity is cleared and is replaced by the previous mapping in the Mapping Graph Area and the focus is shifted to the other object.
- Once a local variable is mapped to a target element, the letter (LV) is displayed next to the mapped target element. This signifies that a local variable has been mapped to the target element. The letter (M) is also displayed indicating the target element has been mapped. Refer to Table of Suffixes for details on suffixes displayed next to a target element.
- Local variables do not allow duplicate names at the same level. You need to right-click to edit the local variable, where you can select the source.
Save the mapping activity and exit the Data Mapper.
You can view and validate the generated mapping XSL, view the target XML and view and validate mapping output, before saving the mapping activity.