Skip to content

Commit

Permalink
Examples revised
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGruen committed Jan 16, 2025
1 parent 3b36b6d commit e2b7d56
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions specifications/xquery-40/src/expressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22086,14 +22086,16 @@ raised <errorref
<example>
<ulist>
<item>
<p>Tokenizes a string, creates a new string from the tokens and returns
<code>"a/b/c"</code>:</p>
<eg role="parse-test">'a b c' -> tokenize(.) -> string-join(., '/')</eg>
<p>Tokenizes a string, counts the tokens, creates a concatenated string and returns
<code>count=3</code>:</p>
<eg role="parse-test">'a b c' -> tokenize(.) -> count(.) -> concat('count=', .)
</eg>
<p>An equivalent expression is:
<eg role="parse-test">
let $string := 'a b c'
let $tokens := tokenize($string)
return string-join($tokens, '/')
let $count := count($tokens)
return concat('count=', $count)
</eg>
</p>
</item>
Expand All @@ -22119,16 +22121,33 @@ return sum($powers)
(1 to 4)
-> for-each(., op('+'))
-> for-each-pair(4 to 7, ., op('>'))
-> some(.)</eg>
-> some(.)
</eg>
<p>An equivalent expression is:
<eg role="parse-test">
let $data := (1 to 4)
let $data := 1 to 4
let $data := for-each($data, op('+'))
let $data := for-each-pair(4 to 7, $data, op('>'))
return some($data)
</eg>
</p>
</item>
<item>
<p>Reduces a long sequence to at most 9 elements, with dots appended,
and returns a single string.</p>
<eg role="parse-test">
$dictionary/word
-> (if(count(.) &lt; 10) then . else (.[1 to 9], '…'))
-> string-join(., '; ')
</eg>
<p>An equivalent expression is:
<eg role="parse-test">
let $words := $dictionary/word
let $chopped := (if(count($words) &lt; 10) then $words else ($words[1 to 9], '…'))
return string-join($chopped, '; ')
</eg>
</p>
</item>
</ulist>
</example>
</div2>
Expand Down

0 comments on commit e2b7d56

Please sign in to comment.