Search code examples
xpathxom

Nodes with case-insensitive content using XOM


I want to query nodes from a XOM document which contains certain value but case insensitive. Something like this:

doc.query('/root/book[contains(.,"case-insentive-string")]')

But it contains is case sensitive.

  1. I tried to use regexes, but it is only XPATH2.0 and XOM does not seem to support it.
  2. I tried contains(translate(."ABCEDF...","abcdef..."),"case-insentive-string")]' failed too.
  3. I tried to match subnodes and read parent attributes using getParent, but there is no method to read parents attributes.

Any suggestions ?


Solution

  • If you are using XOM, then you can use Saxon to run XPath or XQuery against it. That gives you the ability to use the greatly increased function library in XPath 2.0, which includes functions lower-case() and upper-case(), and also the ability (though in a somewhat product-specific way) to choose your own collations for use with functions such as contains() - which means you can do matching that ignores accents as well as case, for example.