0
for $b in doc ("courses.xml") //Course_Catalog/Department/Course
where count($b/Instructors/Lecturer)=0
return count($b)

此代码返回结果:1 1 1 1 1 1 1 1 1 1。我真正想要的是所有的加起来返回数字 10。

如果有人能告诉我如何实现这一目标,我将不胜感激。提前感谢您提供的任何帮助。

4

2 回答 2

1

使用总和:

sum(
  for $b in doc ("courses.xml") //Course_Catalog/Department/Course
  where count($b/Instructors/Lecturer)=0
  return count($b)
)
于 2013-03-17T13:36:32.270 回答
0

您实际上需要计算所有这些元素的数量。

使用

count(doc ("courses.xml")//Course_Catalog/Department/Course[not(Instructors/Lecturer)])
于 2013-03-17T15:08:38.963 回答