2011-10-28 2 views
5

以下のような格付けタグから格付けコードを選択する必要があります。ただし、代理店が「SP」または「SNP」の場合に限ります。今、私は持っています:XPathを使用して複数の可能なテキスト値を選択するにはどうすればよいですか?

./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> 

主なものは、あなたが 'または' として使用しようとしたunion演算子|である代わりに|

./ratings/rating/agency[text()='SNP' or text()='SP']/../code 

答えて

9

のおかげで、

ジャレッド

1

使用ororにそれを変更します。

ratings/rating[agency = ('SNP', 'SP')]/code 
:より自然

./ratings/rating/agency[text()='SNP' or text()='SP']/../code 

あるいは、

ratings/rating[agency[. = 'SNP' or . = 'SP']]/code 

をするXPath 2.0では、シーケンスを使用することができます

関連する問題