('alpha','beta','gamma') => string-join(',')
Result(String) : alpha,beta,gamma
('alpha','beta','gamma') => reverse() => string-join(',')
Result(String) : gamma,beta,alpha
(1 to 3) ! ( . * . ) => string-join(',')
Result(String) : 1,4,9
('a','b','c') ! ('<row>'||.||'</row>') => string-join()
Result(String) : <row>a</row><row>b</row><row>c</row>
( for
$i in (1,2,3),
$square in function($a){$a * $a}
return
$square($i)
) => string-join(',')
Result(String) : 1,4,9
(1,2,3) => for-each( function($a){ $a * $a } ) => string-join(',')
Issue with use of colon (:) in CPI editor Before proceeding ahead, please note that CPI is a bit sensitive to the use of colon that is meant for handling the namespace prefix. In case you happen to use colon in XPath expression, you might come across below error in the editor mostly about the first occurrence of colon. Namespace prefix expression assigned to <step> not defined in Namespace Mapping As a workaround, you can declare the expression in namespace mapping in runtime configuration. Not a clean way, but you can leverage the hack until CPI editor matures further in handling colon in XPath. xmlns:expression=expression |
let $x := 'alpha', $y := 'beta' return concat($x, '|', $y)
Result(String) with colon workaround: alpha|beta
for $x in 'alpha', $y in 'beta' return concat($x, '|', $y)
How to use header or property variables as parameter in XPath ? To access header or property variables in XPath expression, you can simply use $ followed by the variable name. Here is the expression you are left with assuming variable x and y is populated from property.
|
map { 'A':'alpha','B':'beta','G':'gamma' } ? A
Result(String) with colon workaround : alpha
How to use functions from different namespace ? So far, all the functions we used belongs to default function namespace, which allows using the function in shorter notation such as string-join. In case, you wish to use function from default namespace in full notation such as fn:string-join, you will need explicitly declaring the prefix in namespace mapping in runtime configuration separated by semi-colon(;). If you intent to use functions from other namespace, you must always be using the full notation along with namespace mapping declaration.
|
<bookstore>
<book>
<title>t1</title>
<author>X</author>
<price>88</price>
</book>
<book>
<title>t2</title>
<author>Y</author>
<price>22</price>
</book>
<book>
<title>t3</title>
<author>X</author>
<price>33</price>
</book>
</bookstore>
( '<authorlist>',
//book/author => serialize(),
'<authorlist>'
) => string-join()
( '<authorlist>',
//book/author ! ('<author>'||.||'</author>'),
'<authorlist>'
) => string-join()
<authorlist>
<author>X</author>
<author>Y</author>
<author>X</author>
<authorlist>
( '<authorlist>',
distinct-values(//book/author) ! ('<author>'||.||'</author>'),
'<authorlist>'
) => string-join()
<authorlist>
<author>X</author>
<author>Y</author>
<authorlist>
('<booklist>', //book!
('<book>',
title!('<title>'||upper-case(.)||'</title>'),
price!('<price>'||concat('$',.)||'</price>'),
'</book>'),
'</booklist>'
) => string-join()
<booklist>
<book>
<title>T1</title>
<price>$88</price>
</book>
<book>
<title>T2</title>
<price>$22</price>
</book>
<book>
<title>T3</title>
<price>$33</price>
</book>
</booklist>
( for
$a in //book/author=>distinct-values(),
$t in //book[author = $a]/title => serialize()
return
('<author name="', $a ,'">', $t ,'</author>')
) => string-join()
<author name="X">
<title>t1</title>
<title>t3</title>
</author>
<author name="Y">
<title>t2</title>
</author>
//book => sort((), function($b){ $b/author, $b/price })
<book>
<title>t3</title>
<author>X</author>
<price>33</price>
</book>
<book>
<title>t1</title>
<author>X</author>
<price>88</price>
</book>
<book>
<title>t2</title>
<author>Y</author>
<price>22</price>
</book>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |