MmM ...
MmM ...

Reputation: 131

XPath - How to compare string and sequence?

XML in short:

...
<team>
    <capitan>Zdeno Chara</capitan>
    <alernativeCapitan>
        <player>Zdeno Chara</player> <!-- NO Chara, he's the capitan obviously -->
        <player>Someone Else</player>
        <player>Someone Other</player>
    </alernativeCapitan>
</team>
<team>
    <capitan>Abc Edf</capitan>
    <alernativeCapitan>
       <player>Abc Xyz</player>
       <player>Bac Edf</player>
       <player>Abc 123</player>
    </alernativeCapitan>
</team>
...

Q: How to compare one string (capitan) with sequence (alternativeCapitan) in XPath?

I wold like to know if capitain is also written like a alternative capitan / player. Comparasion only in one team. (If so, its wrong. Thats all, doesnt matter if the result will be boolean or number.)

Thanks.

Upvotes: 0

Views: 1441

Answers (1)

har07
har07

Reputation: 89285

The question is not 100% clear for me, maybe you want something like this :

//team[capitan=alernativeCapitan/player]

xpathtester demo

The above XPath will return all team where the capitan is also listed in the alternativeCapitan element. Or if you want the opposite, that is return all team where the capitan is not in the alternativeCapitan :

//team[not(capitan=alernativeCapitan/player)]

Upvotes: 2

Related Questions