如何查询多个兄弟姐妹,但不是全部



我知道如何选择父元素的所有同级节点,并且我知道如何只选择一个。 但是,如果有五个,而我只想按名称选择两个或三个怎么办? 例如,给定此示例 xml 片段:

<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>

如何同时选择标题和作者节点?

我可以使用/book/author 获取标题,使用/book/title 获取标题,但是如何将它们组合成一个查询,就像 SQL 查询一样:选择作者,书籍中的标题?

一定有类似的东西,不是吗?

在 XPath 2.0 中:book/(author|title)

在 XPath 1.0 中:book/author | book/title

最新更新