The <set/> command

The <set/> command is used within custom content to assign a value to a user variable.

The var attribute must be present and contains the name of the variable to be assigned.

The value to be assigned can be specified in any of the following ways:

  • the string or value attributes can be used to assign a literal value (see “Strings and values” for a discussion of strings and values).

  • the copy attribute can be used to fetch the value of another variable.

  • the info attribute can be used to determine information about a string.

  • the telltale attribute can be used to fetch the value from a data telltale.

  • the indicator attribute can be used to fetch the value of a leaf or partition indicator.

  • if none of the above attributes are present the value to be assigned is taken from the content of the command.

    For example:

    <set var="Message">Errors: <Bold>{Count}</Bold></set>

It is an error to use more than one of the above attributes in a single command.

The <set/> command is quite flexible. For example, if you wanted to form a date from a set of attributes you could do something like:

<set var="Date" string="{@yyyy}-{@mm}-{@dd}" />

As you can see, while the <set/> command can only assign to user variables, it can make use of both user and attribute variables in its value or string attributes.

All variables are expanded (resolved) to their proper values prior to the command being executed. Therefore the command:

<set var="Size" value="{@length}" />

assigns the current value of the attribute. If the value of {@length} subsequently changes, the value of {Size} will not. This is a good way to store attributes for use in other mappings, as an attribute variable is valid within a single mapping only.

You can even build the name of a variable from other variables:

<set var="USA-{ZipCode}" string="{@town}" />

so that if the current value of {ZipCode} was 32859 and {@town} was Orlando, FL, then the command would be equivalent to:

<set var="USA-32859" string="Orlando, FL" />

The copy attribute is used to copy the content of one variable to another. Thus if {N} contains 1 and {Number1} contains HeadHoncho, the command:

<set var="Position" copy="Number{N}"/>

would set {Position} to HeadHoncho. For comparison,

<set var="Position" string="Number{N}"/>

would set {Position} to Number1.

Note that

<set var="Position" copy="Number"/>


<set var="Position">{Number}</set>

both produce the same result.

The special value element can be used in the copy attribute when processing an XML fragment.