Using variables consists of two parts: (i) declaring the variable, and (ii) using the variable.
|Note:||Variables are supported in Authentic View only in the Enterprise Editions of Altova products.|
Declaring a variable
A variable can be declared on any template included in the design. It is given a name, a datatype, and a value. Additionally, you can specify whether it is to be editable in the Enterprise editions of Authentic View. The variable will then be in scope on this template and can be used within it. To declare a variable so that it is in scope for the entire document, declare the variable on the root template. A major advantage of declaring a variable only on the template where it is needed is that XPath expressions to locate a descendant node will be simpler.
Declare a variable as follows:
1.Right-click the node template on which the variable is to be created and select the command Define Variables.
2.In the Define Variables dialog that appears (screenshot below), click the Append Variable icon in the top left of the Variables pane, then enter a variable name. The value of the variable is given via an XPath expression. If you wish to enter a string as the value of the variable (as in the first variable in the screenshot below), then enclose the string in quotation marks. In the screenshot below, the value of the SelectGroup variable is the empty string. Otherwise, the text will be read as a node name or a function-call.
3.Setting a variable to Editable (by checking the Editable check box) enables the variable to be edited in Authentic View. In this case, you must also set the datatype value to the correct type, such as xs:string. When a variable is editable, the original value set by the SPS designer can be edited when the Authentic View user makes changes to the document in Authentic View. Such changes can be the explicit editing of the variable (such as when the variable value is created as editable (contents) or an editable text box and this is edited by the Authentic View user), or when a node or value used in the variable's XPath expression is modified by the Authentic View user.
4.If the variable is set to Editable, then two more options relevant to Authentic View are enabled: Undoable and Calc. Checking the Undoable option generates an Undo step for every change made to the variable. The Authentic View user can therefore click through the Undo cycle to retrieve an earlier value of the variable.The Calc value can be either Once or Auto. If this option is set to Once, the variable value is calculated once, when the template containing the variable is evaluated. The value can only be changed when the user explicitly edits the variable (for example, if the variable is created as editable (contents) or an editable text box). On the other hand, if this option is set to Auto, the variable will be re-calculated also each time a node or value used in the variable's XPath expression is modified.
5.You can add as many variables as you like, but the name of a variable must not be the name of an already declared in-scope variable. To delete a variable click the Delete icon in the top right of the pane.
6.Click OK when done. The template tag will now have a \$ icon to indicate that one or more variables have been declared on it.
In this way, variables can be created for each node template that is present in the design. Each of these variables will have a name and a value, and will be in scope within the template on which it was declared. To edit a variable subsequently, right-click the node template on which the variable was created and select the command Define Variables to access the Define Variables dialog.
Using a variable
For a variable to be used at any location, it must be in scope at that location. This means that a variable can only be used within the template on which it was defined. Variables can also be edited in Authentic View so that users can control the display. The edited value is discarded when the SPS is closed.
A variable can be used in any XPath expression, and is referenced in the XPath expression by prefixing its name with a \$ symbol. For example, the XPath expression \$VarName/Name selects the Name child element of the node selected by the variable named VarName.
When you enter an XPath expression in the Edit XPath Expression dialog, in-scope variables appear in a pop-up (see screenshot above). Selecting a variable in the pop-up and pressing Enter inserts the variable reference in the expression.