【发布时间】:2020-02-17 09:59:32
【问题描述】:
我希望在数据库中获取有关 data 的基本元数据。具体来说,被根text 元素包围的line 元素的数量。
类似于我期望的 COUNT 返回 SQL —— 一个整数。
数据库:
thufir@dur:~/flwor/group$
thufir@dur:~/flwor/group$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> open people
Database 'people' was opened in 225.24 ms.
>
> xquery /
<text>
<line>people</line>
<line>joe</line>
<line>phone1</line>
<line>phone2</line>
<line>phone3</line>
<line>sue</line>
<line>cell4</line>
<line>home5</line>
<line>alice</line>
<line>atrib6</line>
<line>x7</line>
<line>y9</line>
<line>z10</line>
</text>
Query executed in 215.13 ms.
>
> exit
See you.
thufir@dur:~/flwor/group$
计算行数:
thufir@dur:~/flwor/group$
thufir@dur:~/flwor/group$ basex each.xq
1
2
3
4
5
6
7
8
9
10
11
12
13thufir@dur:~/flwor/group$
代码:
xquery version "3.0";
for $line in db:open("people")
for $index at $count in $line/text/line
return $count
【问题讨论】:
标签: text count xquery basex flwor