http://www.zorba-xquery.com/modules/store/data-structures/stack
Description
Before using any of the functions below please remember to import the module namespace:
import module namespace stack = "http://www.zorba-xquery.com/modules/store/data-structures/stack";Implementation of stack for node items, using dynamic collections.
Author
Daniel Turcanu, Sorin Nasoi
XQuery version and encoding
xquery version "3.0" encoding "utf-8";
Namespaces
| ann | http://www.zorba-xquery.com/annotations |
| collections-ddl | http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl |
| collections-dml | http://www.zorba-xquery.com/modules/store/dynamic/collections/dml |
| stack | http://www.zorba-xquery.com/modules/store/data-structures/stack |
| ver | http://www.zorba-xquery.com/options/versioning |
Variable Summary
Function Summary
copy($destName as xs:QName, $sourceName as xs:QName) as empty-sequence()Copy all nodes from source stack to a destination stack. | |
create($name as xs:QName) as empty-sequence()Create a stack with this name. | |
empty($name as xs:QName) as xs:booleanChecks if a stack exists and is empty. | |
pop($name as xs:QName) as node()?Return the top node in the stack, and remove it. | |
push($name as xs:QName, $value as node()) as empty-sequence()Add a new node to the stack; the stack will contain a copy of the given node. | |
size($name as xs:QName) as xs:integerCount of nodes in the stack. | |
top($name as xs:QName) as node()?Return the top node in the stack, without removing it. |
Variables
$stack:errNS as xs:string
Errors namespace URI.
$stack:errNA as xs:QName
xs:QName with namespace URI="http://www.zorba-xquery.com/modules/store/data-structures/stack" and local name "errNA"
$stack:errExists as xs:QName
xs:QName with namespace URI="http://www.zorba-xquery.com/modules/store/data-structures/stack" and local name "errExists"
Functions
copy#2
declare %ann:sequential function stack:copy(
$destName as xs:QName,
$sourceName as xs:QName
) as empty-sequence() Copy all nodes from source stack to a destination stack.
If destination stack does not exist, it is created first.
If destination stack is not empty, the nodes are appended on top.
Parameters
$destName as xs:QNamename of the destination stack.$sourceName as xs:QNamename of the source stack.
Returns
empty-sequence()()
Examples
create#1
declare %ann:sequential function stack:create(
$name as xs:QName
) as empty-sequence() Create a stack with this name.
If stack exists, an error is raised.
Parameters
$name as xs:QNamename of the new stack.
Returns
empty-sequence()()
Errors
- stack:errExists if the stack identified by $name already exists.
empty#1
declare function stack:empty(
$name as xs:QName
) as xs:booleanChecks if a stack exists and is empty.
Parameters
$name as xs:QNamename of the stack.
Returns
xs:booleantrue is the stack is empty or does not exist.
Errors
- stack:errNA if the stack identified by $name does not exist.
Examples
pop#1
declare %ann:sequential function stack:pop(
$name as xs:QName
) as node()?Return the top node in the stack, and remove it.
Parameters
$name as xs:QNamename of the stack.
Returns
node()?the top node, or empty sequence if stack is empty.
Errors
- stack:errNA if the stack identified by $name does not exist.
Examples
push#2
declare %ann:sequential function stack:push(
$name as xs:QName,
$value as node()
) as empty-sequence()Add a new node to the stack; the stack will contain a copy of the given node.
Parameters
$name as xs:QNamename of the stack.$value as node()the node to be added.
Returns
empty-sequence()()
Errors
- stack:errNA if the stack identified by $name does not exist.
Examples
size#1
declare function stack:size(
$name as xs:QName
) as xs:integerCount of nodes in the stack.
Parameters
$name as xs:QNamename of the stack.
Returns
xs:integerthe count of nodes.
Errors
- stack:errNA if the stack identified by $name does not exist.
Examples
top#1
declare function stack:top(
$name as xs:QName
) as node()?Return the top node in the stack, without removing it.
Parameters
$name as xs:QNamename of the stack.
Returns
node()?the top node, or empty sequence if stack is empty.
Errors
- stack:errNA if the stack identified by $name does not exist.