Xml xpath计数函数

Xml xpath计数函数,xml,xpath,count,Xml,Xpath,Count,我试图使用XPath计数函数来确定以下查询返回多少个元素 doc("courses.xml") count(//Course[contains(Description,"Cross-listed")]) 下面的代码返回2个course元素 doc("courses.xml") //Course[contains(Description,"Cross-listed")] 但是当我尝试使用上面的count函数返回“2”时,我得到了以下错误 tmpDfWgJ7.xq第2行第1列错误: #doc(

我试图使用XPath计数函数来确定以下查询返回多少个元素

doc("courses.xml")
count(//Course[contains(Description,"Cross-listed")])
下面的代码返回2个course元素

 doc("courses.xml")
//Course[contains(Description,"Cross-listed")]
但是当我尝试使用上面的count函数返回“2”时,我得到了以下错误

tmpDfWgJ7.xq第2行第1列错误: #doc(“courses.xml”)中的XPST0003 XQuery语法错误 计数(//#): 意外标记”(“超出查询末尾 查询中的静态错误


如何更正此问题?

计数(doc(“courses.xml”)//课程[包含(描述,“交叉列表”))

使用以下任一选项:

count(doc("courses.xml") //Course[contains(Description,"Cross-listed")])
doc("courses.xml")/count(.//Course[contains(Description,"Cross-listed")])
或更具可读性的内容

count(doc("courses.xml") //Course[contains(Description,"Cross-listed")])
doc("courses.xml")/count(.//Course[contains(Description,"Cross-listed")])

这也可以。您只需在计数前添加/即可:

doc("courses.xml")
/count(//Course[contains(Description,"Cross-listed")])