質問

I want to call a XQuery function with JavaScript to retrieve data from a XML file. I'm able to call this simple function which doesn't read anything from any file:

<script type="text/javascript" 
        src="mxqueryjs/mxqueryjs.nocache.js"
        ></script>
<script type="application/xquery">
   module namespace m = "http://www.xqib.org/module";

   declare function m:GetNearestLocations($node as node()+) {
     let $message := "Hello XQuery!"
     return $message

   };
</script>

With this JavaScript:

var output = xqib.call(
    'http://www.xqib.org/module',
    'GetNearestLocations',
    center.lat());

The return output is as expected "Hello XQuery!".

Now I want to import a math module so that I can use some of its functions while reading data from a XML file.

Here's what I have but the math module doesn't import and causes XQST0059 error saying that there's no information location to load module with namespace "http://www.w3.org/2005/xpath-functions/math":

<script type="text/javascript" 
        src="mxqueryjs/mxqueryjs.nocache.js"
        ></script>
<script type="application/xquery">
   module namespace m = "http://www.xqib.org/module";
   import module namespace math
     = "http://www.w3.org/2005/xpath-functions/math";

   declare function m:GetNearestLocations($node as node()+) {
     let $message := "Hello XQuery!"
     return $message

   };
</script>

What's is weird about this is that when I use Stylus Studio X15 Entreprise Suite to test the same function the import is working.

Important: I'm using the same JavaScript call when I import or not the Math module, so maybe my problem comes from there but, I don't know how I could fix this.

If you could also guide me a little on what could I set as parameter to m:GetNearestLocations so that I can pass it Integers or Strings

Thanks a lot.

役に立ちましたか?

解決

Now I want to import a math module so that I can use some of its functions while reading data from a XML file.

That sounds reasonable. So your first task will be to find an implementation of the math module for namespace http://www.w3.org/2005/xpath-functions/math that XQiB / MXQuery can process, install it on your server, and point to it from the module import statement, as shown in the module import example on the XQiB web site.

Or alternatively, you may decide that you can work with the math functions in http://www.zorba-xquery.com/zorba/math-functions, which MXQuery (and thus XQiB) appear to support natively. (I see this in the MXQuery documentation but not in the XQiB documentation, so I guess there is the theoretical possibility that XQiB is using an older version of MXQuery -- but it's more likely that the development team just has better things to do with their time than document modules already documented elsewhere.)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top