Created
March 19, 2013 09:41
-
-
Save robbypelssers/5194822 to your computer and use it in GitHub Desktop.
XQuery3.0: Higher-Order functions (Filtering)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: | |
Below I show 2 different ways of using the filter function. Both do exactly the same but one uses | |
an inline function expression while the other uses a named function reference | |
:) | |
(: | |
********************************************************************* | |
Example of using filter with inline function expression | |
********************************************************************* | |
:) | |
return fn:filter(function($person) { $person/@gender = 'female'}, $persons/person) | |
(: | |
********************************************************************* | |
Example of using filter with named function reference (predicate) | |
********************************************************************* | |
:) | |
declare function local:isFemale($person as element(person)) as xs:boolean { | |
$person/@gender = 'female' | |
}; | |
let $isFemale := local:isFemale#1 | |
return fn:filter($isFemale, $persons/person) | |
(: | |
********************************************** | |
XQuery output: | |
********************************************** | |
<person gender="female"> | |
<country>Belgium</country> | |
<name>Person C</name> | |
<age>80</age> | |
</person> | |
<person gender="female"> | |
<country>Netherlands</country> | |
<name>Person E</name> | |
<age>30</age> | |
</person> | |
:) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment