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"?
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']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With