如何将 xpath 传递到 xquery 函数声明中
我使用 Apache Tomcat 的 Exist DB 作为 XML 数据库,并尝试通过将以下 xpath(在 FLWOR 的“let”子句中定义)
$xpath := $root/second/third
传递到本地定义的函数声明中来
declare function local:someFunction($uuid as xs:string?, $xpath as xs:anyAtomicType?)
{
let $varOne := $xpath/fourth[@uuid = $uuid]/fifthRight
let $varTwo := $xpath/fourth[@uuid = $uuid]/fifthLeft
let $combined := ($varOne,$varTwo)
return $combined
};
构造序列 : xquery 沙箱,我得到 Type: xs:anyAtomicType is not Defined。我应该用什么来代替它,或者我应该以不同的方式来做这件事?
预先感谢您的任何建议。
I use Apache Tomcat's Exist DB as an XML database and am trying to construct a sequence by passing the following xpath, defined in FLWOR's 'let' clause:
$xpath := $root/second/third
into a locally defined function declaration, like so:
declare function local:someFunction($uuid as xs:string?, $xpath as xs:anyAtomicType?)
{
let $varOne := $xpath/fourth[@uuid = $uuid]/fifthRight
let $varTwo := $xpath/fourth[@uuid = $uuid]/fifthLeft
let $combined := ($varOne,$varTwo)
return $combined
};
Of course, when entering this in the exist xquery sandbox, I get Type: xs:anyAtomicType is not defined. What should I use in place of it, or should I do this a different way?
Thanks in advance for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现该错误(xs:anyAtomicType 未定义)。但是,也许以下内容可以提供帮助?
如果 $xpath (最初是一个节点)作为原子类型参数传递(因此被原子化),那么当您尝试在函数中导航时,它肯定会抛出类型错误 XPTY0019 (
$xpath/fourth
)。以下代码在您这边工作吗(作为node()*
传递)?(编辑:忘记了星号以允许任意数量的节点)
I could not reproduce the error (xs:anyAtomicType not defined). However, maybe the following can help?
If $xpath (initially a node) is passed as an atomic-type parameter (thus is atomized), it will definitely throw a type error XPTY0019 when you attempt to navigate in your function (
$xpath/fourth
). Does the following code work on your side (passed asnode()*
instead)?(Edit: forgot the star to allow any number of nodes)
像 $root/second/third 这样的表达式通常会生成一系列项目,因此将其视为路径没有帮助。使用类型 xs:anyAtomicType?会将项目强制为原子。
您可以将功能简化为
BTW eXist db 是一个独立的开源项目,不是连接到 Apache 或 Tomcat,尽管它使用 Xalan 和 Lucene 等 Apache 组件
An expression like $root/second/third in general yields a sequence of items so it's not helpful to think of it as a path. Using the type xs:anyAtomicType? will coerce the items to a atom.
You can simplify the function to
BTW eXist db is an independent open source project not connected to Apache or Tomcat although it uses Apache components like Xalan and Lucene