2016-11-08 65 views
2
<w> hello </w> <w> world </w> 

您好,我想知道如何使用xquery从xml文件中检索以下单词。例如。我已将'hello'分配给$ x,我如何返回'world'。非常感谢。xquery - 字符串的以下兄弟

回答

1

有几个方法可以做到这一点,最好的办法可能是依赖于上下文。在一种情况下,你可能只是想获得下一个元素节点:

$x/following-sibling::*[1] 

或者由于某种原因,你可能要算在这两个元素之间的空白文本节点:

$x/following-sibling::node()[2] 
1

你寻找following-sibling轴。

let $document := <document> 
    <w>foo</w> 
    <w>bar</w> 
    <w>hello</w> 
    <w>world</w> 
    <w>batz</w> 
</document> 
let $x := "hello" 
return ($document//w[. eq $x]/following-sibling::w)[1]