Skip to content

Instantly share code, notes, and snippets.

@cfoster
Created September 8, 2014 10:45
Show Gist options
  • Save cfoster/12c782534e69b7564885 to your computer and use it in GitHub Desktop.
Save cfoster/12c782534e69b7564885 to your computer and use it in GitHub Desktop.
Potential Filter Pattern for RXQ
xquery version "1.0-ml";
import module namespace functx = "http://www.functx.com" at
"/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
declare option xdmp:mapping "false";
declare variable $filters-sequence as function(*)* :=
fn:function-lookup(xs:QName("local:upper-case"), 1),
fn:function-lookup(xs:QName("local:reverse"), 1),
fn:function-lookup(xs:QName("local:add-english-northerner"), 1);
declare function local:apply-filters($content, $filters as function(*)*)
{
if(fn:exists($filters)) then
local:apply-filters(
$filters[1]($content),
$filters[2 to fn:last()]
)
else $content
};
declare function local:upper-case($content) {
fn:upper-case($content)
};
declare function local:reverse($content) {
functx:reverse-string($content)
};
declare function local:add-english-northerner($content) {
"eyy oop " || $content
};
local:apply-filters("John Smith", $filters-sequence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment