For example, for the XML below
<CATALOG> <CD title="Empire Burlesque"/> <CD title="empire burlesque"/> <CD title="EMPIRE BURLESQUE"/> <CD title="EmPiRe BuRLeSQuE"/> <CD title="Others"/> <CATALOG>
How to match the first 4 records with xpath like //CD[@title='empire burlesque']
. Is there xpath function to do this? Other solutions like PHP function are also accepted.
XPath 2 has a lower-case (and upper-case) string function. That's not quite the same as case-insensitive, but hopefully it will be close enough:
//CD[lower-case(@title)='empire burlesque']
If you are using XPath 1, there is a hack using translate.
matches() is an XPATH 2.0 function that allows for case-insensitive regex matching.
One of the flags is i
for case-insensitive matching.
The following XPATH using the matches() function with the case-insensitive flag:
//CD[matches(@title,'empire burlesque','i')]
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