The tag <stack.empty> allows to know if the stack is empty. The stack can be indicated via the attribute name or passed as argument.
1 stack.empty
<stack.empty name='name'>
<stack /> ?
</stack.empty>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Aname | string | Stack name. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Estack | Stack |
Returns | |
---|---|
Type | Description |
Boolean | Returns a boolean indicating if the stack is empty (true) or not (false). |
Example
Uses the function stack.empty to know if there is values in a stack.
Copy
<xsql-script name='pop_test'> <body> <stack name='stack1'><number>10</number><string>hello</string></stack> <if> <expr> <not><stack.empty><stack1/></stack.empty></not> </expr> <println> <stack.pop name='stack1' /> </println> </if> </body> </xsql-script>
Example
Travel a stack and obtain its values while there is elements.
Copy
<xsql-script name='pop_test'> <body> <stack name='stack1' /> <stack.push name='stack1'> <number>10</number> </stack.push> <stack.push name='stack1'> <number>20</number> </stack.push> <stack.push name='stack1'> <number>30</number> </stack.push> <println>The stack is: <stack1 /></println> <while> <expr><not><stack.empty name='stack1'/></not></expr> <do> <println>Removed <stack.pop name='stack1' /> from stack</println> </do> </while> </body> </xsql-script>