2010-05-18 41 views
1

我使用Apache Tomcat的存在DB作为一个XML数据库,并正在试图建立在通过下面的XPath的序列,在FLWOR的定义“让”条款:如何通过一个XPath到XQuery函数声明

$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沙箱进入这个时候,我得到的类型:XS:anyAtomicType没有定义。我应该用什么来代替它,或者我应该以不同的方式做到这一点?

在此先感谢您的任何建议。

回答

1

我无法重现错误(xs:anyAtomicType未定义)。但是,也许以下可以帮助?

如果$ xpath(最初是一个节点)作为原子类型参数传递(因此被原子化),当您试图在函数中导航时($xpath/fourth),肯定会抛出XPTY0019类型错误。以下代码是否适用于您(代之以node()*)?

declare function local:someFunction($uuid as xs:string?, $xpath as node()*) 
{ 
    let $varOne := $xpath/fourth[@uuid = $uuid]/fifthRight 
    let $varTwo := $xpath/fourth[@uuid = $uuid]/fifthLeft 
    let $combined := ($varOne,$varTwo) 
    return $combined 
}; 

let $root := 
    <first> 
    <second> 
     <third> 
     <fourth uuid="1"> 
      <fifthLeft>foo</fifthLeft> 
      <fifthRight>bar</fifthRight> 
     </fourth> 
     </third> 
    </second> 
    </first> 
let $xpath :=$root/second/third 
return 
local:someFunction("1", $xpath) 

(编辑:忘了明星允许任何数量的节点)

+0

谢谢xqib队没有连接到Apache或Tomcat独立的开源项目!使用: $ xpath as node()* 解决了我的问题。 我在查看xQuery内置的原子类型的层次结构,但是当然,因为我正在传递一个节点,所以没有将其归类。我真的不明白xQuery中的数据类型定义,并没有找到一组很好的教程来说明如何使用它们。 再次感谢。 – topmulch 2010-05-20 13:29:43

0

像$根/第二/第三,一般收益率的项目序列的表达,因此把它作为是没有帮助路径。使用类型xs:anyAtomicType?将强制项目给一个原子。

可以简化功能

declare function local:y($uuid as xs:string?, $xpath as item()*) 
{ 
    $xpath/fourth[@uuid = $uuid]/(fifthRight,fifthLeft) 
}; 

BTW eXist db是虽然它使用的是Apache组件,如Xalan和Lucene的

+0

嗨克里斯,我用物品()*,也工作。虽然,我需要函数来返回一个序列。 我很抱歉地指出Exist DB是Apache Tomcat项目的一部分 - 我也知道这一点。事实上,在另一台机器上,我将Jetty作为Web服务器运行,而不是Apache。 谢谢你的回应。 – topmulch 2010-05-20 13:35:56