The <switch>..<case> command

The <switch> command is used to transfer control to one of a set of enclosed <case> blocks. The overall structure is:

<switch>
  <case>…</case>
  <case>…</case>
  …
</switch>

Each <case> block is set out just like an <if> command. The system will evaluate the <case> conditions one by one. If a condition evaluates to true, then the corresponding block is processed, after which control passes on to the end of the <switch>. In other words at most one <case> block will be processed.

If none of the conditions is true, then the <switch> does nothing at all.

It is permitted to omit the condition from the final <case>, in which case the corresponding block will always be processed. This provides a fallback behavior if none of the other <case> blocks succeed.

For example, to emit a greeting in the appropriate language:

<switch>
  <case var="@lang" target="fr">
     Bonjour!
  </case>
  <case var="@lang" target="de">
     Guten Tag!
  </case>
  <case>
     Hi there!
  </case>
</switch>

Note that it is not necessary for every <case> to have the same var.