xpath 中的逗号运算符,它像 c 吗? [英] comma operator in xpath, is it like c?

查看:29
本文介绍了xpath 中的逗号运算符,它像 c 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    <xsl:variable name="html-output-name" 
         select="(if(@index and @index eq 'true') 
             then concat($default-name, '.html') 
             else (), 
         @html-output-name,
         @output-name, 
         $default-html)[1]" />

我知道if"在做什么,但我不确定如何理解命令中的其余项,然后是最后的 [1].这是否等于列表中的第一个非空项目?"

I see what the 'if' is doing, but I'm not sure how to make sense of the rest of the items in the command, and then the [1] at the end. Does this add up to 'the first non-empty item in the list?"

推荐答案

来自 http://www.w3.org/TR/xpath20/#construct_seq

定义:构造一个序列是通过使用 逗号运算符,它评估每个它的操作数并连接结果序列,按顺序,变成一个单个结果序列

Definition: One way to construct a sequence is by using the comma operator, which evaluates each of its operands and concatenates the resulting sequences, in order, into a single result sequence

部分 BNF:

[2] Expr ::=<代码>ExprSingle(","ExprSingle)*

来自 http://www.w3.org/TR/xpath20/#id-filter-expr

[定义:过滤器表达式仅由 主要组成表达式后跟零个或多个谓词.结果过滤器表达式由主要返回的项目表达式,通过应用每个过滤依次谓词,从左开始工作向右.] 如果没有谓词指定,结果就是主表达式的结果.这由 a 返回的项目的排序过滤器表达式与它们的相同在主要结果中排序表达.上下文位置是根据项目分配给项目结果中的顺序位置序列.第一个上下文位置是 1.

[Definition: A filter expression consists simply of a primary expression followed by zero or more predicates. The result of the filter expression consists of the items returned by the primary expression, filtered by applying each predicate in turn, working from left to right.] If no predicates are specified, the result is simply the result of the primary expression. The ordering of the items returned by a filter expression is the same as their order in the result of the primary expression. Context positions are assigned to items based on their ordinal position in the result sequence. The first context position is 1.

问题:

这是否加起来是'第一个列表中的非空项目?

Does this add up to 'the first non-empty item in the list?

答案:不完全是.这将选择列表中的第一项.没有空的项目,而是空的序列.并且因为没有嵌套序列(正式的元组),它们只是作为一个平面序列连接起来.

Answer: Not quite. This selects the first item in the list. There are no empty item, but empty sequence. And because there aren't nested sequence (formaly tuples), they are just concatenated as a flat sequence.

这篇关于xpath 中的逗号运算符,它像 c 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆