gpt4 book ai didi

function - xquery中的条件计数

转载 作者:行者123 更新时间:2023-12-02 09:14:06 24 4
gpt4 key购买 nike

我有一个带有子节点的节点,其内容如下:

<parent>
<child>a</child>
<child>b</child>
<child>c</child>
<child>a</child>
<child>c</child>
</parent>

我想计算内容为“a”的子项数量。

到目前为止我已经尝试过:

count($node/child/'a')

但这只给了我所有 child 的数量。执行此操作的正确方法是什么?

最佳答案

试试这个:

let $parent :=
<parent>
<child>a</child>
<child>b</child>
<child>c</child>
<child>a</child>
<child>c</child>
</parent>
return count($parent/child[text() = 'a'])

这也算<child>a<foobar/>b</child> ,因为文本节点 a被发现。要比较所有文本上下文,您可以使用 $parent/child[. = 'a'] .

关于function - xquery中的条件计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39038765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com