xpath lowercase - Is there xpath function to do this?

做~自己de王妃 提交于 2021-01-21 08:11:41

问题


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:


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']


来源:https://stackoverflow.com/questions/24183701/xpath-lowercase-is-there-xpath-function-to-do-this

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!