Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath lowercase - Is there xpath function to do this?

Tags:

xml

xpath

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?

like image 894
tobias Avatar asked Jun 12 '14 11:06

tobias


People also ask

Which XPath function would you use to transform character to uppercase?

XPath/XQuery upper-case function.

Are XPath case sensitive?

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.

What are valid XPath functions?

About XPath Functions. Node Set Functions. number last() number position() number count(node-set)


1 Answers

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']
like image 64
helderdarocha Avatar answered Oct 17 '22 20:10

helderdarocha