如何使用 XPath 选择多个可能的文本值? [英] How to use XPath to select multiple possible text values?
本文介绍了如何使用 XPath 选择多个可能的文本值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须从类似于下面的评级标签中选择评级代码,但仅当机构是SP"或SNP"时.现在我有:
I have to select rating codes out of a ratings tag similar to the one below, but only when the agency is 'SP' or 'SNP'. Right now I have:
./ratings/rating/agency[text()='SNP'|text()='SP']/../code
虽然这似乎不起作用.我做错了什么?
This doesn't seem to be working though. What am I doing wrong?
<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>
谢谢,
贾里德
推荐答案
主要是您尝试用作或"的联合运算符 |
.将其更改为或
:
The main thing is the union operator |
which you've tried to use as an 'or'. Change it to or
:
./ratings/rating/agency[text()='SNP' or text()='SP']/../code
或者更自然地,
ratings/rating[agency[. = 'SNP' or . = 'SP']]/code
在 XPath 2.0 中,您可以使用序列:
In XPath 2.0, you can use a sequence:
ratings/rating[agency = ('SNP', 'SP')]/code
这篇关于如何使用 XPath 选择多个可能的文本值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文