Database Reference
In-Depth Information
declare function local:sort-callback ( $ node as node ()) as xs:string {
upper-case ( normalize-space ( $ node ))
};
Now we can create the index using this function:
let $ node-set as element ()+ := doc ( '/db/path/to/nodeset/document' )/ * / Node
let $ index-id as xs:string := 'SORTINDEX'
let $ sort-index := sort:create-index-callback (
$ index-id ,
$ node-set ,
local:sort-callback # 1 ,
()
)
With this we've created a sort index for our nodes with identifier SORTINDEX . The
sort:create-index-callback always returns the empty sequence () . Its fourth
argument can be an XML fragment for specifying the sort order and what to do with
empty values:
<options order? = "ascending" | "descending"
empty? = "least" | "greatest"
Using the created sort index in a FLWOR expression is easy:
for $ node in $ node-set
order by sort:index ( $ index-id , $ node )
return
string ( $ node )
This returns the expected:
a B c D e F
Once created, a sort index is available globally, systemwide. All queries, in any ses‐
sion, can access it. So, if you need sort indexes in your application, it would be best to
create them in some kind of initialization script. If you want to check whether a sort
index exists, use sort:has-index .
sql
Description
Database access using JDBC
Namespace
sql="http://exist-db.org/xquery/sql"
Type/default status
Java; enabled in $EXIST_HOME/conf.xml ; enabled in $EXIST_HOME/extensions/
build.properties
 
Search WWH ::




Custom Search