此xpath表达式返回文本值列表:
/some/xpath/expression/@Image
(此表达式返回几个值)
还有我的另一个xpath表达式:
/other/xpath/expression[starts-with(@Image, 'value')]
我需要选择给定遗产的所有
/other/xpath/expression/@Image
属性,这些属性的值以/some/xpath/expression/@Image
获得的值之一开头。如何合并这些表达式?这可能吗?我需要这样的东西/other/xpath/expression[starts-with(@Image, /some/xpath/expression/@Image)]
最佳答案
这个XPath
/some/xpath/expression/@Image[starts-with(.,'value')]
将选择给定遗产的所有
@Image
属性,其值以字符串value
开头。更新以解决评论中的后续问题:
如果
'value'
不是文字,而是要从文档的其他位置获取,则只需将'value'
替换为选择值的XPath:/some/xpath/expression/@Image
[starts-with(., /other/xpath/expression/@Image)]
关于xml - XPath:起始于和值列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46526218/