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%7DTEI%5B1%5D/Q%7Bhttp://www.tei-c.org/ns/1.0%7Dt...]'.
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> };