XPath 中不区分大小写的匹配? [英] case-insensitive matching in XPath?

查看:43
本文介绍了XPath 中不区分大小写的匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,对于下面的 XML

For example, for the XML below

<CATALOG>
    <CD title="Empire Burlesque"/>
    <CD title="empire burlesque"/>
    <CD title="EMPIRE BURLESQUE"/>
    <CD title="EmPiRe BuRLeSQuE"/>
    <CD title="Others"/>
<CATALOG>

如何像 //CD[@title='empire burlesque'] 一样将前 4 条记录与 xpath 匹配.是否有 xpath 函数来执行此操作?也接受其他解决方案,如 PHP 函数.

How to match the first 4 records with xpath like //CD[@title='empire burlesque']. Is there xpath function to do this? Other solutions like PHP function are also accepted.

推荐答案

XPath 2 具有小写(和大写)字符串函数.这与不区分大小写并不完全相同,但希望它足够接近:

XPath 2 has a lower-case (and upper-case) string function. That's not quite the same as case-insensitive, but hopefully it will be close enough:

//CD[lower-case(@title)='empire burlesque']

如果您使用的是 XPath 1,则有一个 使用翻译破解.

If you are using XPath 1, there is a hack using translate.

这篇关于XPath 中不区分大小写的匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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