Sujan
Sujan

Reputation: 1562

Checking multiple values (and) in a node in Xpath

XML:

<codes>
    <code>AP</code>
    <code>BS</code>
</codes

I am trying to check <code> if it contains both 'AP' and 'BS' using following xpath.

/codes[contains(code, 'AP') and contains(code, 'BS')]

but is not working. Is there any other way to get to the solution?

Upvotes: 0

Views: 2175

Answers (2)

splash58
splash58

Reputation: 26153

If you really need contains but not exactly equal, use such Xpath

/codes[code[contains(., 'AP')] and code[contains(., 'BS')]]

Upvotes: 2

michael.hor257k
michael.hor257k

Reputation: 117083

I suspect you want:

/codes[code='AP' and code='BS']

Upvotes: 1

Related Questions