在使用XPath 1.0的replicate
中的City
处,我只返回 unique Name
值吗? >
state = 'Washington'
到目前为止,我已经尝试了以下XPath查询:
<StateDataSet>
<State>
<Name>Washington</Name>
<City>Seattle</City>
<business>Starbucks</business>
</State>
<State>
<Name>Washington</Name>
<City>Seattle</City>
<business>Amazon</business>
</State>
<State>
<Name>Washington</Name>
<City>Redmond</City>
<business>Microsoft</business>
</State>
<State>
<Name>Washington</Name>
<City>Redmond</City>
<business>Starbucks</business>
</State>
<State>
<Name>Washington</Name>
<City>Seattle</City>
<business>Dicks</business>
</State>
<State>
<Name>Alaska</Name>
<City>Anchorage</City>
<business>Starbucks</business>
</State>
<State>
<Name>Oregon</Name>
<City>Portland</City>
<business>Starbucks</business>
</State>
<State>
<Name>Alaska</Name>
<City>Gnome</City>
<business>Starbucks</business>
</State>
</StateDataSet>
这返回了华盛顿的城市,但价值并不唯一。我使用xpathtester.com
测试了查询我在做什么错?我的查询基于get-distinct-values-within-specific-attributes
答案 0 :(得分:2)
此XPath,
/StateDataSet/State[Name ='Washington' and
not(City = preceding-sibling::State[Name='Washington']/City)]
/City
将使用City
在State
元素中选择唯一的Name = 'Washington'
元素:
<City>Seattle</City>
<City>Redmond</City>
根据要求。