我必须从类似下面的评级标签中选择评级代码,但仅限于代理商为“SP”或“SNP”时。现在我有:
./ratings/rating/agency[text()='SNP'|text()='SP']/../code
这似乎不起作用。我做错了什么?
<ratings>
<rating>
<agency>SP</agency>
<provider>SP</provider>
<type>LONG TERM</type>
<currencyType>LOCAL</currencyType>
<description>SP Standard LT LC rating</description>
<code>BBB+</code>
<date>2011-09-07</date>
</rating>
</ratings>
谢谢,
贾里德
答案 0 :(得分:12)
主要的是你试图用作'或'的联合运算符|
。将其更改为or
:
./ratings/rating/agency[text()='SNP' or text()='SP']/../code
或者更自然地,
ratings/rating[agency[. = 'SNP' or . = 'SP']]/code
在XPath 2.0中,您可以使用序列:
ratings/rating[agency = ('SNP', 'SP')]/code
答案 1 :(得分:1)
使用or
代替|
./ratings/rating/agency[text()='SNP' or text()='SP']/../code