XQuery/Getting URL Parameters

Motivation
You want to create an XQuery that takes a parameter from the calling URL.

Format
The format of a calling URL that uses the HTTP Get or POST command is: : / /xquery.xq?param1=123&param2=456 Where param1 is the first parameter with a value of 123 and param2 is the second parameter with a value of 456.

Note that question mark is used to start the parameters and the ampersand is used to separate parameters. Remember to include "amp;" following the &.

Checking Data Types
Additionally you can check the data types using the XML Schema data types and the castable as operator.

Script to echo all URL parameters
echo-parameters.xq

Here are the results of sending the parameters "a=1&b=2" to this XQuery:

echo-parameters.xq?a=1&b=2

Adding a Debug Parameter
It is very common that you want to conditionally turn on part of a transform to get additional information during the debugging process.