# Elementname: `Switch`

## Description

Create an if-then-else construct. The test attribute of each Case commands is evaluated until it yields true. The contents of the Case gets executed. If no test succeeds, the (optional) Otherwise gets executed.

Allowed attributes: (none)

Child elements: Case, Otherwise

Parent elements: AtPageCreation, AtPageShipout, B, Case, Color, Columns, Contents, Element, Fontface, ForAll, I, Include, Layout, Li, Loop, NoBreak, Otherwise, Overlay, Paragraph, PlaceObject, Position, Record, SavePages, SetVariable, Span, Table, Tablefoot, Tablehead, Td, Text, Textblock, Tr, U, URL, Until, While

### Attributes

## Example

    <Record element="data">
      <SetVariable variable="counter" select="3"/>
      <Switch>
        <Case test=" $counter &lt; 5">
          <SetVariable variable="text" select="'Less than 5'"/>
        </Case>
        <Case test=" $counter &lt; 20">
          <SetVariable variable="text" select="'Less than 20'"/>
        </Case>
        <Otherwise>
          <SetVariable variable="text" select="'Larger or equal to 20'"/>
        </Otherwise>
      </Switch>
      <PlaceObject>
        <Textblock>
          <Paragraph><Value select="$text"/></Paragraph>
        </Textblock>
      </PlaceObject>
    </Record>

## Info

You have to be careful to encode the test with the rules of XML: that is »less« must be written as `<`, since `<` must not be part of text contents.

A Switch may be part of nearly all commands. It dissolves and only the contents of the Case or Otherwise gets replaced by the whole construct.

## See also

Case Otherwise

# 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
- DefineColorprofile
- 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.6.1 | Start page | Command reference | Other language: German