Search code examples
javascriptmarklogicmarklogic-8

xQuery to JavaScript require with multiple files


When converting an xQuery script tot JavaScript, I have this line where two XQY files are combined into a single module namespace.

How do I do this in JavaScript?

Original

import module namespace obj = "http://marklogic.com/solutions/obi/object" at 
                     "/ext/obi/lib/object-service-lib.xqy", "/ext/obi/lib/object-lib.xqy";

Not working:

var obj = require("/ext/obi/lib/object-service-lib.xqy", 
                                                "/ext/obi/lib/object-lib.xqy");

Error

[javascript] XDMP-TOOMANYARGS: var obj = require("/ext/obi/lib/object-service-lib.xqy", "/ext/obi/lib/obje -- Too many args, expected 1 but got 2


Solution

  • You could perhaps require the two libraries separately, and then merge them into one manually, but I would skip the hassle, and just treat the two separately. I see not much benefit of merging them, neither in XQuery, nor in SJS..

    HTH!