7. Conditional processing with `if`
| Chapter 1. Language syntax |

## 7. Conditional processing with `if`

    if -> 'if' test '{' block_contents '}'
          [ 'elseif' test '{' block_contents '}' ]*
          [ 'else' '{' block_contents '}' ]

    test -> boolean_XPath_expression

    block_contents -> [ command | if | foreach ]*

The `test` tests found after `if`, `elseif`, ..., `elseif` are evaluated in turn until a test evaluates as `true()`. When this happens, the evaluation of tests stops there and the `block_contents` following the successful test is run. If no test evaluates as `true()`, then the `block_contents` following `else`, if any, is run.

Examples:

    if $table-container and count($table-container//td) = 1 {
        replace(copy(.), $table-container);
    }

    if ./node() {
        unwrap-element();
    } else {
        delete();
    }

    if @href {
        remove-attribute("name");
    } elseif ./node() {
        unwrap-element();
    } else {
        delete();
    }

6. Commands |  | 8. Repetition with `for-each`