<set>

<set> is a special operation that allows for user-defined variables and for setting their values. Values may be constant or defined by a 1010data Macro Language query; however, all values set must be scalar.

Description

Both <set> and <setv> allow you to set values for user-defined variables. <set> is used for block variables, while <setv> is used for dynamic variables. While <set> requires a variable name, <setv> allows the variable name to be set with programmatic logic.

Syntax

<set [USER_DEFINED_VAR_1]="[VALUE_1]" ...
          [USER_DEFINED_VAR_N]="[VALUE_N]"/>

Alternate Syntax

<set>
  <[ARBITRARY_VARIABLE_AS_TAG]>
    [ARBITRARY_VALUE_OF_VAR]
  </[ARBITRARY_VARIABLE_CLOSING_TAG]>
</set>

Attributes

[USER_DEFINED_VAR_x]
Accepts a string that will act as a user-defined variable. The variable name must begin with a lowercase alphabetic character and consist only of lowercase alphanumeric characters, digits, and/or underscores.

The block element may include any number of additional attributes, which may be used as parameters in the Macro Language code contained within the element. The value of a user-defined variable (e.g., my_var) is substituted wherever a scalar expression containing a reference to it (e.g., {@my_var}) appears within the block element.

Example 1

<base table="default.lonely"/>
<set text="Some text here."/>
<willbe name="text" value="'{@text}'"/>

Example 2

<base table="default.lonely"/>
<set>
  <greetings>
    <foreach name="Bob,Carol,Ted,Alice">Hello, {@name}!> 
    </foreach>
  </greetings>
</set>
<willbe name="greetings" value="'{@greetings}'" format="width:52"/>

Example 3

The following code sets a variable called pkg_str to a package of strings:

<base table="default.lonely"/>
<set pkg_str="Stooge1:'Moe',Stooge2:'Larry',Stooge3:'Curly'"/>
<willbe name="Stooges" value="{@pkg_str}"/>

Additional Information

<set> uses the following shorthand to construct lists and packages, as follows:

Data Structure Syntax
package <set pkg="{key:'value'}"/>
list <set lst="{'value1','value2'}"/>
package of strings <set pkg_str="key:'value'"/>
package from string <set pkg_from_str="{{@$pkg_str}}"/>
list of strings <set lst_str="'v1','v2'"/>
list from string <set lst_from_str="{{@$lst_str}}"/>