I have a RESTXQ path/function that is supposed to retrieve a document fragment, restricted to an XPath expression that is given as a query parameter, i.e., as a string. The list of possible fragment XPaths has been calculated using path() by another function, and the user of a Web application may choose to retrieve any of the fragments.

An example for such a path would be '/Q{http://www.tei-c.org/ns/1.0}TEI[1]/Q{http://www.tei-c.org/ns/1.0}text[1]/Q{http://www.tei-c.org/ns/1.0}front[1]/Q{http://www.tei-c.org/ns/1.0}div[3]'.

Is there a better solution than the following, whose performance is of course quite poor (around 2 seconds execution time for the given documents)? I’m thinking of something like saxon:evaluate() or the XSLT 3 instruction xsl:evaluate.

Maybe I’m just unaware of the obvious solution based upon XQuery 3 or a BaseX extension.

Gerrit

declare
  %rest:path("/content/fragment/{$db}/{$doc}")
  %rest:query-param("xpath", "{$xpath}")
  %rest:GET
  function page:get-frags(
    $db as xs:string,
    $doc as xs:string,
    $xpath as xs:string
  )
    as item()*
{
  <response>
    { for $doc in db:open($db, $doc)
      return $doc//*[path(.) eq $xpath] }
  </response>
};
_______________________________________________
BaseX-Talk mailing list
BaseX-Talk@mailman.uni-konstanz.de
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

Reply via email to