XQuery/Manipulating URIs

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Motivation[edit | edit source]

Sometimes you need to be able to manipulate the URI of your own XQuery. This is useful when you need to call your own XQuery with different parameters. For example if you have an XQuery that returns the first 20 rows in a query but you want to add a Get Next 20 Records button you may want to simply call yourself with additional parameters for what record to start with, in this case start at record 21.

This program demonstrates some XQuery functions that are not part of the original XQuery specification but are required for precise web server XQuery functionality.

The functions are:

  • eXist request:get-uri() - Returns the URI of the current request within the web server. For example


  • eXist request:get-url() - Returns the full URL including the server and port.


  • eXist request:get-query-string() - Returns the full query string passed to the servlet (without the initial question mark).
  • eXist system:get-module-load-path() - returns the path to the place where a module has been loaded from
  • eXist system:get-exist-home() - returns the base of the eXist web root

Sample Program[edit | edit source]

xquery version "1.0";
declare namespace system="http://exist-db.org/xquery/system";
declare namespace request="http://exist-db.org/xquery/request";
declare option exist:serialize "method=html media-type=text/html indent=yes";

let $get-uri := request:get-uri()
let $get-url := request:get-url()
let $module-load-path := system:get-module-load-path()
let $exist-home := system:get-exist-home()
let $path := substring-after($module-load-path, 'xmldb:exist://embedded-eXist-server')
let $replace := replace($module-load-path, 'xmldb:exist://embedded-eXist-server', '')

   <title>URI Path Example</title>
   <h1>Sample URI manipulation with XPath</h1>
      <table border="1">
            <td>substring-after(system:get-module-load-path(), 'xmldb:exist://embedded-eXist-server')</td>
            <td>replace(system:get-module-load-path(), 'xmldb:exist://embedded-eXist-server', '')</td>