Associates a value with a variable name. The value can be a simple value or a more complex one consisting of several elements.

Child elements

Attribute, Column, Columns, Copy-of, Element, ForAll, Loop, Paragraph, SortSequence, Switch, Table, TableNewPage, Tablehead, Tablerule, Td, Tr, Value

Parent elements

AtPageCreation, AtPageShipout, Case, Contents, ForAll, Include, Layout, Loop, Otherwise, Record, SavePages, While


select (XPath expression, optional)

The value of the contents.

trace (optional)

Show information about the assignment in the log file.


Show information.


Don’t show information (default).

type (optional, since version 4.3.10)

Set the data type of the variable. Currently only supported for MetaPost variables.


The default (any) datatype for variables in the speedata layout language.


A MetaPost CMYK color.


A MetaPost RGB color.

variable (text)

The name of the variable that holds the contents.


Variables have global scope.


<Record element="product">
  <SetVariable variable="wd" select="5"/>
    <Textblock width="{ $wd }">
        <Value select="$articlenumber"/>

The following example shows a more complex scenario: you can collect complex elements in a variable.

<Record element="products">
  <SetVariable variable="articletext"/>
  <ProcessNode select="article"/>
      <Value select=" $articletext "/>

<Record element="article">
  <SetVariable variable="articletext">
    <!-- the previous contents is added -->
    <Value select="$articletext"/>
      <Value select=" @description "/>

See also

The sections Programming and Create and use images with MetaPost.