Reputation: 41
I have a feed XML and I want to select items
in the file.
<xml>
<item>
...
</item>
<item>
...
</item>
<item>
...
</item>
</xml>
But the user can pass the tag name like <Item>
or <ITEM>
or something like that. How can I write an XPath to select the items with case insentitive?
Upvotes: 0
Views: 50
Reputation: 167571
In XPath 1.0 you can use e.g. //*[translate(local-name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'item']
but as I said in a comment, consider to preprocess the XML in a transformation step to normalize the case of letters before using normal XPath selectors like //item
in the second step.
Upvotes: 1
Reputation: 33361
There are 2 ways to do this:
lower-case
string function://*[lower-case(name())='item']
matches()
XPATH 2.0 functionmatches()
function flags is i
for case-insensitive matching.//*[matches(name(),'item','i')]
UPD
I do not know about real case-insensitive matching with XPath 1.0
What you can do is to use or
case, like:
//*[name()='item' or name()='Item' or name()='ITEM']
Upvotes: 1