# Otherwise operator

XPath 4.0 proposes an additional operator: `otherwise`. The expression `A otherwise B` returns the value of `A` unless it is an empty sequence, in which case it returns the value of `B`. For example, the expression:

chapter[title='Introduction'] otherwise chapter

returns the chapter(s) entited "Introduction" if such a chapter exists; otherwise it returns the first chapter.

The precedence of the operator is greater than arithmetic operators (so `\$n div \$m otherwise 1` means `\$n div (\$m otherwise 1)`), but less than the "union" operator (so `a/b/c otherwise 0` means `(a/b/c) otherwise 0`).
{"ft_lang_label":"__label__en","ft_lang_prob":0.66126126,"math_prob":0.8747044,"size":553,"snap":"2021-43-2021-49","text_gpt3_token_len":135,"char_repetition_ratio":0.20582879,"word_repetition_ratio":0.0,"special_character_ratio":0.238698,"punctuation_ratio":0.10280374,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9767908,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-11-28T20:46:13Z\",\"WARC-Record-ID\":\"<urn:uuid:a051b096-542b-4ecc-91d1-f3c3c937179f>\",\"Content-Length\":\"6113\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:80cb5dba-e763-436c-8b8b-ea37defe3d76>\",\"WARC-Concurrent-To\":\"<urn:uuid:a0cf7a11-5185-4ef2-b8fa-bb0148065ff8>\",\"WARC-IP-Address\":\"79.170.198.133\",\"WARC-Target-URI\":\"https://www.saxonica.com/html/documentation11/v4extensions/other-xpath-extensions/otherwise.html\",\"WARC-Payload-Digest\":\"sha1:CT233KWBAPMDSV6SJ4UK3C2OBLIB65LU\",\"WARC-Block-Digest\":\"sha1:U6LZQDB5KPKCKNKELN3BBNN224BLHMDG\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964358591.95_warc_CC-MAIN-20211128194436-20211128224436-00376.warc.gz\"}"}