javascript - 使用 javascript 调用 XQuery

标签 javascript xquery xquery-3.0

我想用 JavaScript 调用 XQuery 函数以从 XML 文件中检索数据。我可以调用这个不从任何文件读取任何内容的简单函数:

<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>

使用这个 JavaScript:

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

返回输出符合预期“Hello XQuery!”。

现在我想导入一个数学模块,以便在从 XML 文件读取数据时可以使用它的一些函数。

这是我所拥有的,但数学模块没有导入并导致 XQST0059 错误,指出没有信息位置来加载 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>

奇怪的是,当我使用 Stylus Studio X15 Entreprise Suite 测试相同的功能时,导入工作正常。

重要:当我导入或不导入 Math 模块时,我使用相同的 JavaScript 调用,所以我的问题可能来自那里,但我不知道如何解决这个问题。

如果您还可以指导我将什么设置为 m:GetNearestLocations 的参数,以便我可以将其传递给整数或字符串

非常感谢。

最佳答案

现在我想导入一个数学模块,以便在从 XML 文件读取数据时可以使用它的一些函数。

这听起来很有道理。因此,您的首要任务是为命名空间 http://www.w3.org/2005/xpath-functions/math 找到数学模块的实现。 XQiB/MXQuery 可以处理,将其安装在您的服务器上,并从模块导入语句中指向它,如 the module import example 所示在 XQiB 网站上。

或者,您可以决定可以使用 http://www.zorba-xquery.com/zorba/math-functions 中的数学函数,其中 MXQuery(以及 XQiB)似乎原生支持。 (我在 the MXQuery documentation 中看到了这一点,但在 the XQiB documentation 中没有看到,所以我猜理论上 XQiB 使用旧版本的 MXQuery 的可能性是存在的——但更有可能的是开发团队只是有更好的事情要做时间比其他地方已经记录的文档模块要多。)

关于javascript - 使用 javascript 调用 XQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17815256/

相关文章:

javascript - react : Map function with two parameters

javascript - 是否可以隐藏/禁用 ImageMapster 中的区域?

function - 确定 XQuery 中出现的频率

java - XPTY0004 : Required item type of first operand of '>' is numeric; supplied value has item type xs:string

xml - 如何在xquery中的 "if statements"语句中使用 "let"

javascript - 加载大量图像而不卡顿的最佳方式。

javascript - 从 json 制作 slider

sql - 使用 XQuery 替换 SQL Server 中的 xml 命名空间前缀

xquery - data() 和 string() 的区别