我想在包含"数据库"的所有书籍上返回结果。属于"字段"内的属性。
for $e in //testbook[field="databases"]
return $e/title
.xml
文件的示例:
<?xml version="1.0" encoding="UTF-?>
<testbook>
<book>
<author> AuthorGuy </author>
<title> theBook</title>
<field> databases </field>
</book>
</testbook>
答案 0 :(得分:1)
有两个问题:
<title/>
和<field/>
元素包含在<book/>
元素中,而不是<testbook/>
的直接子元素,修复了路径表达式。<field/>
标记包含用空格包装的字段,使用contains($string, $needle)
代替简单比较。一个工作示例:
let $document := document{<testbook>
<book>
<author> AuthorGuy </author>
<title> theBook</title>
<field> databases </field>
</book>
</testbook>}
for $e in $document//testbook[contains(book/field, "databases")]
return $e/book/title