XQuery/操作 URI
外觀
< XQuery
有時您需要能夠操作自己的 XQuery 的 URI。當您需要使用不同的引數呼叫自己的 XQuery 時,這很有用。例如,如果您有一個 XQuery 返回查詢中的前 20 行,但您想新增一個 **獲取下一個 20 條記錄** 按鈕,您可能只想使用有關從哪裡開始的附加引數來呼叫自己,在本例中從記錄 21 開始。
該程式演示了一些 XQuery 函式,這些函式不是原始 XQuery 規範的一部分,但對於精確的 Web 伺服器 XQuery 功能是必需的。
這些函式是
- eXist request:get-uri() - 返回 Web 伺服器中當前請求的 URI。例如
/exist/rest/db/test/my-query.xq
- eXist request:get-url() - 返回包括伺服器和埠的完整 URL。
http://www.example.com:8080/exist/rest/db/test/my-query.xq
- eXist request:get-query-string() - 返回傳遞給 servlet 的完整查詢字串(沒有初始問號)。
- eXist system:get-module-load-path() - 返回模組載入位置的路徑
- eXist system:get-exist-home() - 返回 eXist Web 根目錄的基地址
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(system:get-module-load-path(), 'xmldb:exist://embedded-eXist-server', '')</td>
<td>{$replace}</td>
</tr>
</table>
</body>
</html>