XPath:开始于和值列表
XPath: starts-with and lists of values
此 xpath 表达式 returns 文本值列表:
/some/xpath/expression/@Image
(这个表达式returns几个值)
还有我的另一个 xpath 表达式:
/other/xpath/expression[starts-with(@Image, 'value')]
我需要 select 给定遗产的所有 /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')]
将 select 给定遗产的所有 @Image
属性,其值以字符串 value
.
开头
更新以解决评论中的后续问题:
如果 'value'
不是文字而是从文档的其他地方获取,只需将 'value'
替换为 select 值的 XPath:
/some/xpath/expression/@Image
[starts-with(., /other/xpath/expression/@Image)]
如果我们绑定一些变量可能会更清楚:
<xsl:variable name="S" as="xs:string*" select="/some/xpath/expression/@Image"/>
还有我的另一个 xpath 表达式:
<xsl:variable name="O" as="xs:string*" select=/other/xpath/expression"/>
我需要 select 所有 /other/xpath/expression/@Image 属性,其值以 $s 中的值之一开头。
那就是
$O[some $s in $S satisfies(starts-with(., $s)]
技术说明:在 XPath 中很少需要这样的表达式,但这里会发生这种情况,因为您正在执行的联接不是等值联接。为此,您需要两个范围变量:上下文项 "."
可用于其中一个,但另一个需要明确。在 XSLT 中,您有时可以使用 current()
作为第二个范围变量。
此 xpath 表达式 returns 文本值列表:
/some/xpath/expression/@Image
(这个表达式returns几个值)
还有我的另一个 xpath 表达式:
/other/xpath/expression[starts-with(@Image, 'value')]
我需要 select 给定遗产的所有 /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')]
将 select 给定遗产的所有 @Image
属性,其值以字符串 value
.
更新以解决评论中的后续问题:
如果 'value'
不是文字而是从文档的其他地方获取,只需将 'value'
替换为 select 值的 XPath:
/some/xpath/expression/@Image
[starts-with(., /other/xpath/expression/@Image)]
如果我们绑定一些变量可能会更清楚:
<xsl:variable name="S" as="xs:string*" select="/some/xpath/expression/@Image"/>
还有我的另一个 xpath 表达式:
<xsl:variable name="O" as="xs:string*" select=/other/xpath/expression"/>
我需要 select 所有 /other/xpath/expression/@Image 属性,其值以 $s 中的值之一开头。
那就是
$O[some $s in $S satisfies(starts-with(., $s)]
技术说明:在 XPath 中很少需要这样的表达式,但这里会发生这种情况,因为您正在执行的联接不是等值联接。为此,您需要两个范围变量:上下文项 "."
可用于其中一个,但另一个需要明确。在 XSLT 中,您有时可以使用 current()
作为第二个范围变量。