Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop the "fn:" in MarkLogic functions?

Is there a way with MarkLogic to not have to prefix every single fn: function with that prefix? I've seen lots of codes on the Internet that show me that I don't need it.

Things can get rather verbose, you know? fn:not(fn:contains(...)), instead of not(contains(...))

Thoughts?

Thanks!

like image 817
Mr Mikkél Avatar asked Oct 22 '13 23:10

Mr Mikkél


1 Answers

Like you, I prefer not to type fn: in front of all my fn:functions.

In normal XQuery main modules you don't need the fn: prefix because that's the default function namespace and used for all unprefixed functions. You do however need fn: in library modules because they change their default function namespace to that of the library module namespace. This means the library functions can call each other without any prefix.

But you can change it back! Here's the header code to do the switch back.

xquery version "1.0-ml";
module namespace util = "http://markmail.org/util";
declare default function namespace "http://www.w3.org/2005/xpath-functions";

Or if you're on the older 0.9-ml:

xquery version "0.9-ml"
module "http://markmail.org/util"
declare namespace util = "http://markmail.org/util"
default function namespace = "http://www.w3.org/2003/05/xpath-functions"

It puts the module in a given namespace, assigns util to that namespace, then assigns the default back to the normal fn: one.

After this switch, function calls and definitions without a prefix will default to the fn: prefix; that means all functions in the util library should explicitly use a util: prefix. (Personally, I think that's cleaner anyway.)

like image 53
hunterhacker Avatar answered Nov 03 '22 02:11

hunterhacker