Xml XPath:以和值列表开始
此xpath表达式返回文本值列表:Xml XPath:以和值列表开始,xml,xpath,xpath-2.0,Xml,Xpath,Xpath 2.0,此xpath表达式返回文本值列表: /some/xpath/expression/@Image (此表达式返回多个值) 下面是我的另一个xpath表达式: /other/xpath/expression[starts-with(@Image, 'value')] <xsl:variable name="O" as="xs:string*" select=/other/xpath/expression"/> 我需要选择给定遗产的所有/other/xpath/expression/
/some/xpath/expression/@Image
(此表达式返回多个值)
下面是我的另一个xpath表达式:
/other/xpath/expression[starts-with(@Image, 'value')]
<xsl:variable name="O" as="xs:string*" select=/other/xpath/expression"/>
我需要选择给定遗产的所有
/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'
不是文本,而是从文档中的其他位置获取,只需用选择值的XPath替换'value'
:
/some/xpath/expression/@Image
[starts-with(., /other/xpath/expression/@Image)]
如果我们绑定一些变量,可能会更清楚:
<xsl:variable name="S" as="xs:string*" select="/some/xpath/expression/@Image"/>
技术说明:在XPath中很少需要这样的表达式,但在这里发生这种情况是因为您正在进行的连接不是equi连接。为此,您需要两个范围变量:上下文项
“
可用于其中一个,但另一个需要显式。在XSLT中,有时可以使用current()
作为第二个范围变量。可能重复的'@RNS,nope,不需要,我需要选择给定遗产的所有/other/xpath/expression/@Image
属性,这些属性的值以我通过/some/xpath/expression/@Image
@user23343436453:Answer updated获得的一个值开始,以解决后续问题。
$O[some $s in $S satisfies(starts-with(., $s)]