18

For example, for the xml below

<REPORT ID="TimekeeperListEdited" BoundId="Timekeeper" BoundType="ReportObject" />

How to match the first record with xpath like //*[@BoundId='TimeKeeper']. Is there xpath function to do this?

1

1 Answer 1

30

If you are using XPath 2.0, you can use the lower-case() function:

//*[lower-case(@BoundId) = 'timekeeper']

In case your use is restricted to XPath 1.0, you can convert cases with the translate() function which replaces each character in your string (first argument) that matches any character in the second argument, with the character that occurs in the same position in the string passed as the third argument:

//*[translate(@BoundId, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'timekeeper']

or, if you are dealing with a particular case and the string you are testing is fixed (and not a variable coming from some other part in your program), you can simply translate the characters that interest you:

//*[translate(@BoundId, 'k', 'K') = 'TimeKeeper']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.