Reputation: 13850
I have a XML:
<entities>
<entity attribute="attribute-value-1 attribute-value-2">value1</entity>
<entity attribute="attribute-value-5 attribute-value-7 attribute-value-8">value2</entity>
</entities>
How can I a select using XPath an entity with attribute value of "attribute-value-7"
?
Upvotes: 3
Views: 1185
Reputation: 111621
You have to be careful to avoid inadvertently matching superstrings such as "attribute-value-77" or "wrong-attribute-value-7".
Use the idiom commonly used to match HTML @class
attributes:
//entity[contains(concat(' ', normalize-space(@attribute), ' '),
' attribute-value-7 ')]
//entity[tokenize(@attribute,'\s+')='attribute-value-7']
Upvotes: 5