diff --git a/specifications/grammar-40/xpath-grammar.xml b/specifications/grammar-40/xpath-grammar.xml index a44c2aa95..c4a4fa858 100644 --- a/specifications/grammar-40/xpath-grammar.xml +++ b/specifications/grammar-40/xpath-grammar.xml @@ -1553,6 +1553,11 @@ ErrorVal ::= "$" VarName + + + -> + + diff --git a/specifications/xquery-40/src/expressions.xml b/specifications/xquery-40/src/expressions.xml index dd0bfe35e..7b54f83dc 100644 --- a/specifications/xquery-40/src/expressions.xml +++ b/specifications/xquery-40/src/expressions.xml @@ -22054,6 +22054,104 @@ raised + + Pipeline operator + + + + With the pipeline operator ->, the result of an expression + can be bound to the context value before evaluating another expression. + + + + + + + + +

+ The pipeline operator -> evaluates an expression and + binds the result to the context value before evaluating another expression.

+ +

Each operation E1 -> E2 is evaluated as follows: + Expression E1 is evaluated to a sequence S. + S then serves in turn to provide an inner + (with the context value set to S) for an evaluation of E2 in the + dynamic context. + Unlike the , the result of E1 is bound + just once and as a whole to the context value. +

+ +

The following examples illustrate the use of pipeline operators:

+ + + +

Tokenizes a string, counts the tokens, creates a concatenated string and returns + count=3:

+ 'a b c' -> tokenize(.) -> count(.) -> concat('count=', .) + +

An equivalent expression is: + +let $string := 'a b c' +let $tokens := tokenize($string) +let $count := count($tokens) +return concat('count=', $count) + +

+
+ +

Calculates the sum of powers of 2 and returns + 2046.

+ (1 to 10) ! math:pow(2, .) -> sum(.) +

An equivalent expression is: + +let $powers := ( + for $exp in 1 to 10 + return math:pow(2, $exp) +) +return sum($powers) + +

+
+ +

Doubles the values of a sequence, compares the values pairwise with another + sequence, checks if some comparisons were successful, and returns + true.

+ +(1 to 4) +-> for-each(., op('+')) +-> for-each-pair(4 to 7, ., op('>')) +-> some(.) + +

An equivalent expression is: + +let $data := 1 to 4 +let $data := for-each($data, op('+')) +let $data := for-each-pair(4 to 7, $data, op('>')) +return some($data) + +

+
+ +

Reduces a long sequence to at most 9 elements, with dots appended, + and returns a single string.

+ +$dictionary/word +-> (if(count(.) < 10) then . else (.[1 to 9], '…')) +-> string-join(., '; ') + +

An equivalent expression is: + +let $words := $dictionary/word +let $chopped := (if(count($words) < 10) then $words else ($words[1 to 9], '…')) +return string-join($chopped, '; ') + +

+
+
+
+
+ Simple map operator (!)