XQuery/Parsing Query Strings

= Motivation = Normal http query strings use the ampersand (&) character in order to differentiate between different terms in a query string. However, because ampersands also are used as the start of entities within HTML and XML, this can make it difficult encoding parametric content into XML links, and it moreover makes it difficult to visually decipher query strings.

This program illustrates how to parse query strings using alternative delimiters (such as the semi-colon).

This program demonstrates some standard 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-method
 * exist util:unescape-uri
 * exist request:get-query-string
 * exist request:get-parameter
 * exist request:get-parameter-names

Namespace
module namespace common= "http://www.example.org/xmlns/common" ;

Platform

 * eXist

common:get-parameters
This base function retrieves the query string from the URI, parses the string using the given delimiter and creates an XML structure of the form

common:get-parameter
This function retrieves a sequence of string values corresponding to the values for a given parameter key given in the query string. Note that while typically there will be only one string in the sequence, if you have a query string of the form ?a=val1;b=val2;a=val3 then get-parameter("a","",";") will return ("val1","val3")

common:get-parameter-names
This function retrieves the name of each query string key (once and only once per key).

Example Program
Assumes query string of

let $msg := common:get-parameter("c","",";") return $msg returns new message

returns

let $seq1 := common:get-parameter("a",0,";") return sum(for $n in $seq1 return number($n))

returns 13