[xquery-talk] Recursion or not - how to (re)query an API

Bridger Dyson-Smith bdysonsmith at gmail.com
Mon Jan 18 08:09:33 PST 2016

Hi all,

I'm struggling with getting a working example of the following problem: I'm
sending a query to an API that returns some data and, if the data set is
large enough, a resumption token to requery the API.

I'm stuck at the point of how to generate the new query URL, while still
processing the new data. Is the best idea to create a function that will
update a new request to the API, or is there a different approach that can
be used?

I've made several attempts with functions -- the latest non-working
examples are below -- and I'm missing... something, but I don't know what.

Thanks for any guidance you can provide.

(: sample query :)

declare variable $query external := '
declare variable $sessionToken := '&sessionToken=';
declare variable $resToken := '';

(:doesn't work:)
declare function local:getPID($in as document-node()) as xs:anyAtomicType*

(:doesn't work:)
declare function local:reQuery(
  $in as document-node(),
  $rQ as xs:untypedAtomic*) as document-node()
  let $rQ := $in/*:listSession/*:token/text()
  return (
    if ($rQ) then
      local:getPID(doc("$in" || "&sessionToken=" || "$rQ"))
    else ()

(: this works processing the descendant elements but doesn't recurse :)
for $result in fn:doc($query)/*:result
let $resToken := $result/*:listSession/*:token/text()
let $pid := $result/*:resultList/*:objectFields/*:pid/text()
return (

(: sample returned from query; e.g. $result :)
<result xmlns="http://www.fedora.info/definitions/1/0/types/" xmlns:types="
http://www.fedora.info/definitions/1/0/types/" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20160118/b6d0ecc5/attachment.html>

More information about the talk mailing list