Skip to main content

Set variable

XML
<set var="var" key="(no key)">
string
</set>

<set /> sets the value of a variable.

These three statements are semantically equivalent:

XML
<set var="var[key]">value</set>
<set var="var.key">value</set>
<set var="var" key="key">value</set>

These two statements are semantically equivalent:

XML
<set var="var[]">value</set>
<array:push var="var">value</array:push>

Attributes

NameTypeDescriptionDefined By
varvarVariable name set
keystringKey set

Results

BindingTypePredicate
varstringN/A

Examples

Setting regular variables

XML
<set var="firstname">Bill</set>
<set var="lastname">Gates</set>
<output>$firstname $lastname</output>
<!-- Bill Gates -->

Setting array items implicitly

XML
<set var="names[bg]">Bill Gates</set>
<set var="names.sj">Steve Jobs</set>
<output>$names.bg and $names[sj] are competitors!</output>
<!-- Bill Gates and Steve Jobs are competitors! -->

Setting array items explicitly

XML
<set var="names" key="bg">Bill Gates</set>
<set var="names" key="sj">Steve Jobs</set>
<output>$names.bg and $names[sj] are competitors!</output>
<!-- Bill Gates and Steve Jobs are competitors! -->