XQuery/Adder

Motivation
We would like to create a simple XQuery that takes two arguments and returns the sum of the two numbers.

Example Program Using URL Parameters (HTTP GET)
Call this like.

Accumulating Adder
To make this into an interactive application, we can extend the script to create an XHTML document containing a Form.

The script computes the new sum from the URL parameters (if any) and returns a minimal XHTML document containing a Form which both reports the sum and prompts for new inputs. Note the embedded XQuery expressions (in curly braces) which interpolates the computed values into the created XML element. The state of the computation, the value of the accumulator, is retained in a hidden input in the form.

Try this

Clearing the accumulator
To support the operation of clearing the accumulator, we can add a couple of submit buttons to the form. The presence of the 'Clear' action is used to set the inputs to zero.

Try this with

Example Using Session Variables
An alternative way of holding the state of this computation is in session variables. The session module in eXist provides the necessary functions.

Try this with