我必须从类似下面的评级标签中选择评级代码,但仅限于代理商为“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>
谢谢,
贾里德
主要是联盟操作符|你试图用作’或’.将其更改为或:
原文链接:https://www.f2er.com/xml/292155.html./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