xpath 小写 - 是否有 xpath 函数来执行此操作? [英] xpath lowercase - Is there xpath function to do this?

查看:35
本文介绍了xpath 小写 - 是否有 xpath 函数来执行此操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如对于下面的xml

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

如何像 ///*[@BoundId='TimeKeeper'] 一样将第一条记录与 xpath 匹配.是否有 xpath 函数来执行此操作?

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

推荐答案

如果您使用的是 XPath 2.0,您可以使用 lower-case() 函数:

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

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

如果您的使用仅限于 XPath 1.0,您可以使用 translate() 函数转换大小写,该函数替换字符串(第一个参数)中匹配的每个字符第二个参数中的任何字符,出现在作为第三个参数传递的字符串中相同位置的字符:

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

这篇关于xpath 小写 - 是否有 xpath 函数来执行此操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆