Skip to content

Instantly share code, notes, and snippets.

@line-o
Last active February 17, 2018 11:31
Show Gist options
  • Select an option

  • Save line-o/773dad49d0dcecad7dfd6a02af1005d5 to your computer and use it in GitHub Desktop.

Select an option

Save line-o/773dad49d0dcecad7dfd6a02af1005d5 to your computer and use it in GitHub Desktop.
Examples for new xquery features available in exist-db >=3.6.1
xquery version "3.1";
(: new xquery features :)
declare function local:sequence-to-array ($sequence as item()*) as array(*) {
array { $sequence }
};
declare function local:array-to-sequence ($array as array(*)) as item()* {
$array?*
};
declare function local:filter-numerical ($sequence as item()*) as item()* {
filter($sequence, function ($item) { ($item castable as xs:integer) })
};
declare function local:filter-other ($sequence as item()*) as item()* {
filter($sequence, function ($item) { not($item castable as xs:integer) })
};
declare function local:render ($strings as xs:string*) as xs:string* {
``[-(`{string-join($strings, ')-(')}`)-]``
};
declare variable $local:input := 'a 4 b 1 d c 2 3';
$local:input
=> tokenize(?,' ')
=> local:filter-numerical(?)
=> (function ($s) { filter($s, function ($i) { xs:integer($i) > 1 })})(?)
=> local:sequence-to-array(?),
$local:input
=> tokenize(?,' ')
=> local:filter-other(?)
=> sort(?)
=> local:render(?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment