, , /, .
XQuery / :
declare function ActIf($collection as element(*)*, $index as xs:integer, $indexMax as xs:integer, $condition as xs:string, $count as xs:integer) as xs:integer
{
if($index <= $indexMax) then
let $element := $collection[$index]
if($element/xyz/text() eq $condition) then
(: here you can call a user-defined function before continuing to the next element :)
ActIf($collection, $index + 1, $indexMax, $condition, $count + 1)
else
ActIf($collection, $index + 1, $indexMax, $condition, $count)
else (: no more items left:)
$count
};
XPath:
for $element at $count in $collection[xyz = $condition]
return
(: call your user-defined function :)
myFunction($collection[xyz = $condition])
A recursive solution can be quite useful if you want to implement something more complex with XQuery ...
source
share