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?
XPath/XQuery upper-case function.
XPath is a case-sensitive language. Keywords in XPath use lowercase characters and are not reserved. Names in XPath expressions are allowed to be the same as language keywords.
About XPath Functions. Node Set Functions. number last() number position() number count(node-set)
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']
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