XPath 1.0 可以做通用量化("for all")吗?

Can XPath 1.0 do universal quantification ("for all")?

假设我有以下 XML(我的实际 XML 的高度简化示例):

<myxml>
    <cities>
        <city>Amsterdam</city>  
        <city>London</city>
        <city>Paris</city>
    </cities>
    <hotelLocations>
        <hotelLocation>Amsterdam</hotelLocation>
        <hotelLocation>Berlin</hotelLocation>
    </hotelLocations>   
</myxml>

现在我想知道 hotelLocation 中的值是否确实作为城市存在。我试图在一个 XPath 语句中做到这一点:

//hotelLocation=//city

但是,如果 hotelLocations 之一匹配,这将返回 "true",而不是 我只希望它在 all[=27 时返回 true =] 的 hotelLocations 个存在于城市实体中。

知道 one XPath 语句是否可行吗?

instead I only want it to give true as all of the hotellocations exist in the cities entities. Any idea if this is possible with one xpath statement at all?

是的,以下 XPath 表达式将执行您的请求:

not(//hotelLocation[not(. = //city)])

这样读:本文档的city个元素中应该没有hotelLocation个字符串值不存在的元素。这在逻辑上等同于做出请求的声明:hotelLocation 元素给出的所有城市也必须存在于本文档的 city 元素中。