# Functions and recursion

### Simple function with two parameters

    xquery version "3.0";

    declare function local:greet($name as xs:string, $lang as xs:string?) as xs:string {
        if ($lang = "de") then
            "Hallo " || $name
        else if ($lang = "es") then
            "Hola " || $name
        else
            "Hello " || $name
    };

    local:greet("Susi", "de"),
    local:greet("Susi", "es"),
    local:greet("Susi", "en"),
    local:greet("Susi", ())

### Recursion: compute the factorial of a given integer

    xquery version "1.0";

    declare function local:fact($n as xs:integer) {
        if ($n eq 1) then
            $n
        else
            $n * local:fact($n - 1)
    };

    local:fact(6)