XPath 1.0 to find if an element’s value is in a list of values

You can check multiple conditions inside the same square brackets:

/Location/Addr[State="TX" or State="AL" or State="MA"]

Or if you have a really long list, you can create a list of states and use the contains() function.

/Location/Addr[contains('TX AL MA', State)]

This will work fine for two-letter state abbreviations. If you want to make it more robust for longer strings you could add some spaces on the ends and check for _TX_, _AL_, etc. (where the underscores are spaces).

/Location/Addr[contains(' TX AL MA ', concat(' ', State, ' '))]

Leave a Comment