case-insensitive matching in xpath?

Ethan picture Ethan · May 23, 2010 · Viewed 108.6k times · Source

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.

Answer

Matthew Flaschen picture Matthew Flaschen · May 23, 2010

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.