Variables can be created in the XML editor with the xe:variable widget.



Overview

You can store the result of an XPath expression in a variable and use it in other widgets.

Example

It is especially useful for the following application scenarios: 

  • parameterization of an included partial dialogue (parts). The embedded partial dialogue uses variables that are declared outside the partial dialogue.
  • Optimizing performance when evaluating an XPath expression is prohibited and the result is needed in several places in the dialogue. In this case, the result can be temporarily stored in a variable and this variable can be accessed from any application site when it is needed.

Configuration

The name identifies the variable clearly within its scope of application. The value can be either a constant, for example, string or number, or an XPath expression can be specified. All XPath expressions must start with "=:".
Via its name ($name) the variable is accessible from within other XPath expressions (but not from anywhere else).
The contents of a variable can be any XPath result, for example, a text, a list of values, a single XML element or a list of XML nodes.

<xe:variable name="name" value="…"/>
CODE

As soon as they are generated, variables are declared and their value gets computed. This happens usually only once during the building of the dialogue. In order to have the XPath expression re-evaluated, a listener (xe:listen-to) must be placed right under the variable widget. For each notification, the XPath expression is re-calculated and the content of the variable is updated.

<xe:variable name="test"
             value="=:cs:asset()[@censhare:function.my-tasks='1']">
<xe:listen-to source="@type"/>
</xe:variable>
CODE


Scope of Variables: 

The visibility of a variable is limited to the widget container (group), in which it was defined, plus recursively to all its child widgets.

<xe:group id="A">
          <xe:group id="B">
          </xe:group>
         <xe:variable name="var1" value="1"/>
        <xe:group id="C">
       <xe:variable name="var2" value="2"/>
       <xe:group id="D">
     </xe:group>
     </xe:group>
    <xe:group id="E">
   </xe:group>
<xe:group>
CODE
In the above example, the variable var1 is visible in the groups A, C, D and E. In Group B, it is not yet known during the building of the dialogue, even though it is declared within the same container (A), but only after group B. The variable var1 can only be used in groups C and D.

Variables of a parent container can be "overwritten" in a lower container when a variable of the same name is created. The new value is limited to the scope of the overriding variable.
For example, the variable var1 with value 1 in the container C is overwritten. In Groups C and D it now has the value 2, whereas in groups A, B and E it still has the value 1.

<xe:group id="A">
      <xe:variable name="var1" value="1"/>
       <xe:group id="B">
        </xe:group>
        <xe:group id="C">
        <xe:variable name="var1" value="2"/>
       <xe:group id="D">
      </xe:group>
     </xe:group>
     <xe:group id="E">
   </xe:group>
<xe:group>
CODE
Examples

1. Variables are declared in order to parameterize an integrated partial dialog.

<xe:group>
<xe:variable name="id" value="=:asset/@id"/>
<xe:variable name="title" value="=:asset/@name"/>
          
  <!-- Part that uses parameters "id" and "title" -->
  
<xe:include key="part2"/>
</xe:group>
CODE

2. The result of an asset search is saved in a variable. This variable is subsequently used inside a generator in a "For-each Loop".

<xe:variable name="mytasks"
   value="=:cs:asset()[@censhare:function.my-tasks='1']"/>
          <xe:group visible="=:boolean($mytasks)">
          <xe:foreach align"down">
          <xe:generator expression="=:$mytasks"/>
       <xe:label value="=:asset/@name"/>
   </xe:foreach>
</xe:group>
CODE