在 XPATH 中获取属性的子字符串 [英] Getting a substring of an attribute in XPATH
本文介绍了在 XPATH 中获取属性的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定
<foo>
<bar baz="Hello, World!">
</foo>
除了@baz 的最后 4 个字符之外,我如何处理?我的尝试之一是:
How do I all but the last 4 characters of @baz? One of my attempts was:
/foo/bar/@baz[substring( ., 0, -4 )]
推荐答案
使用:
substring(/foo/bar/@baz, string-length(/foo/bar/@baz)-3)
请注意表达式中的 3
.
以下错误:
substring(/foo/bar/@baz, string-length(/foo/bar/@baz)-4)
因为这将返回 baz
属性的字符串值的最后 5 个字符.
because this returns the last 5 characters of the string value of the baz
attribute.
这篇关于在 XPATH 中获取属性的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文