使用 XOM 具有不区分大小写内容的节点
我想从包含特定值但不区分大小写的 XOM 文档中查询节点。像这样的东西:
doc.query('/root/book[contains(.,"case-insentive-string")]')
但它包含区分大小写。
- 我尝试使用正则表达式,但它是 只有XPATH2.0,而XOM好像没有 支持它。
- 我试过
contains(translate(."ABCEDF...","abcdef..."),"case-insentive-string")]'
也失败了。 - 我尝试匹配 子节点并读取父节点属性 使用 getParent,但没有 读取父母属性的方法。
有什么建议吗?
I want to query nodes from a XOM document which contains certain value but case insensitive. Something like this:
doc.query('/root/book[contains(.,"case-insentive-string")]')
But it contains is case sensitive.
- I tried to use regexes, but it is
only XPATH2.0 and XOM does not seem
to support it. - I tried
contains(translate(."ABCEDF...","abcdef..."),"case-insentive-string")]'
failed too. - I tried to match
subnodes and read parent attributes
using getParent, but there is no
method to read parents attributes.
Any suggestions ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 XOM,那么您可以使用 Saxon 对其运行 XPath 或 XQuery。这使您能够使用 XPath 2.0 中大大增加的函数库,其中包括函数 lower-case() 和 upper-case(),并且还能够(尽管以某种特定于产品的方式)选择您自己的排序规则与 contains() 等函数一起使用 - 这意味着您可以进行忽略重音和大小写的匹配。
If you are using XOM, then you can use Saxon to run XPath or XQuery against it. That gives you the ability to use the greatly increased function library in XPath 2.0, which includes functions lower-case() and upper-case(), and also the ability (though in a somewhat product-specific way) to choose your own collations for use with functions such as contains() - which means you can do matching that ignores accents as well as case, for example.
正确的编写方法是:
其中
$vUpper
和$vLower
被定义为(应替换为)字符串:and
和 < code>$vCaseInsentiveString 定义为(应替换为)特定的不区分大小写的字符串。
例如,给定以下 XML 文档:
以下 XPath 表达式(用相应的字符串替换变量):
选择此元素:
说明:
contains()
函数的两个参数都转换为小写,然后进行比较。The proper way to write this is:
where
$vUpper
and$vLower
are defined as (should be substituted by) the strings:and
and
$vCaseInsentiveString
is defined as (should be substituted by) the specific case-insensitive string.For example, given the following XML document:
the following XPath expression (substitute the variables by the corresponding strings):
selects this element:
Explanation: Both arguments of the
contains()
function are converted to lower-case, and then the comparison is performed.