# Elementname: `SetVariable`

## Description

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

Allowed attributes: select, trace, variable

Child elements: Attribute, Columns, Copy-of, Element, ForAll, Loop, Paragraph, SortSequence, Switch, TableNewPage, Tablehead, Tablerule, Td, Tr, Value

Parent elements: AtPageCreation, AtPageShipout, Case, Contents, ForAll, Include, Layout, Loop, Otherwise, Record, SavePages, Until, While

### Attributes

select (XPath Expression, optional)

  The value of the contents.

trace (optional)

  Show information about the assignment in the log file.

  yes: | Show information.
  no: | Don't show information (default).

variable (text)

  The name of the variable that holds the contents.

### Remarks

Variables have global scope.

## Example

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

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"/>
      <PlaceObject>
        <Textblock>
          <Value select=" $articletext "/>
        </Textblock>
      </PlaceObject>
    </Record>

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

## See also

Value

# Commands

- A
- Action
- AddSearchpath
- AtPageCreation
- AtPageShipout
- AttachFile
- Attribute
- B
- Barcode
- Bold
- BoldItalic
- Bookmark
- Box
- Br
- Case
- Circle
- Color
- Column
- Columns
- Compatibility
- Contents
- Copy-of
- DefineColor
- DefineFontalias
- DefineFontfamily
- DefineTextformat
- Element
- Fontface
- ForAll
- Frame
- Grid
- Group
- Groupcontents
- HSpace
- Hyphenation
- I
- Image
- Include
- Initial
- InsertPages
- Italic
- Layout
- Li
- LoadDataset
- LoadFontfile
- Loop
- Makeindex
- Margin
- Mark
- Message
- NewPage
- NextFrame
- NextRow
- NoBreak
- Ol
- Options
- Otherwise
- Output
- Overlay
- PDFOptions
- Pageformat
- Pagetype
- Paragraph
- PlaceObject
- Position
- PositioningArea
- PositioningFrame
- ProcessNode
- Record
- Regular
- Rule
- SaveDataset
- SavePages
- SetGrid
- SetVariable
- SortSequence
- Span
- Stylesheet
- Sub
- Sup
- Switch
- Table
- TableNewPage
- Tablefoot
- Tablehead
- Tablerule
- Td
- Text
- Textblock
- Tr
- Trace
- Transformation
- U
- URL
- Ul
- Until
- VSpace
- Value
- While

Version: 3.4.1 | Start page | Command reference | Other language: German