Login
Quick Search

Switch Expression

by dizzzz at 13-3-2011 12:31; Wiki ID: SwitchExpressionExample

The Switch Expression is a welcome addition to the XML Query Language. This example presents its potential.

xquery version "3.0";
let $animal := "Cat"
return
 switch ($animal) 
   case "Cow" case "Calf" return "Moo"
   case "Cat" return "Meow"
   case "Duck" return "Quack"
   default return "What's that odd noise?"

returns

Meow

Note the sequence of switch case clauses

case "Cow" case "Calf" return "Moo"
sharing the same return expression.

The expression is available starting eXist-db 1.5

Links
Latest Posts
AtomicWiki 0.4