XQuery/Manipulating URIs: Difference between revisions

From Wikibooks, open books for an open world
Jump to navigation Jump to search
[unreviewed revision][unreviewed revision]
Content deleted Content added
Line 5: Line 5:


The functions are:
The functions are:
* [[/eXist/]] request:get-uri()
* [[/eXist/]] '''request:get-uri()''' - Returns the URI of the current request within the web server. For example
<code>/exist/rest/db/test/my-query.xq</code>
* [[/eXist/]] request:get-url()
* [[/eXist/]] request:get-query-string()
* [[/eXist/]] '''request:get-url()''' - Returns the full URL including the server and port.
<code>http://www.example.com:8080/exist/rest/db/test/my-query.xq</code>
* [[/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()
* [[/eXist/]] system:get-module-load-path()
* [[/eXist/]] system:get-exist-home()
* [[/eXist/]] system:get-exist-home()

Revision as of 00:06, 15 November 2007

Motivation

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/rest/db/test/my-query.xq

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

http://www.example.com:8080/exist/rest/db/test/my-query.xq

  • 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()
  • eXist system:get-exist-home()

Sample Program

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', '')

return
<html>
   <head>
   <title>URI Path Example</title>
   </head>
   <body>
   <h1>Sample URI manipulation with XPath</h1>
      <table border="1">
         <thead>
           <tr>             <th>In</th>
             <th>Out</th>
           </tr>
         </thead>
         <tr>
            <td>request:get-url()</td>
            <td>{$get-url}</td>
         </tr>
         <tr>
            <td>request:get-uri()</td>
            <td>{$get-uri}</td>
         </tr>
         <tr>
             <td>system:get-module-load-path()</td>
             <td>{$module-load-path}</td>
         </tr>
         <tr>
             <td>system:get-exist-home()</td>
             <td>{$exist-home}</td>
         </tr>
         <tr>
            <td>substring-after(system:get-module-load-path(), 'xmldb:exist://embedded-eXist-server')</td>
            <td>{$path}</td></tr>
         <tr>
            <td>replace</td>
            <td>{$replace}</td>
         </tr>        
    </table>
  </body>
</html>

Execute