Search code examples
xmlxpathtranslate

XPath expression - translate to lowercase


I have the following XPath expression:

"//*[@name='outputFormat']/ows:Value"

I would like to make it case insensitive, as in some XML files outputFormat may also be OutputFormat etc. I know the translate function in XPath 1.0 and would like to apply it for this expression. My simple question is: how? I tried with this:

"//*[@Translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='outputformat']/ows:Value"

but this throws an error. Any help (including tips what is the best way to handle this kind of problems in XPath) would be appreciated.


Solution

  • Your @ should be attached to name since it's the attribute you're matching, while translate() is a function. Try this:

    "//*[translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'outputFormat']/ows:Value"