Additions:
See Also [[BuiltinVariables Builtin Variables]]
Additions:
See Also [[BasicSyntax Basic Syntax]]
See Also [[CommandTie tie]]
See Also [[CommandTie tie]]
Deletions:
See Also [[CommandTie]]
Additions:
====Tied Variables====
See the [[CommandTie tie]] command for how to tie xquery expressions to variables.
See Also [[BasicSyntax]]
See Also [[CommandTie]]
See the [[CommandTie tie]] command for how to tie xquery expressions to variables.
See Also [[BasicSyntax]]
See Also [[CommandTie]]
Deletions:
Additions:
====Sequence Append====
Sequences can be appended using the syntax
VAR+=value
This is a syntax shortcut for
VAR=($VAR,value)
or
VAR=<[ $VAR , value ]>
If the variable doesn't exist it is created as if assigned using =.
Example: Create a sequence of integers 1 to 10 then append 20 to 30
A=<[ 1 to 10 ]>
A+=<[ 20 to 30 ]>
echo $A
Result
1 2 3 4 5 6 7 8 9 10 20 21 22 23 24 25 26 27 28 29 30
Example Create an element then append to it
A=<[ <foo>text</foo> ]>
A+=<[ <bar>text</bar> ]>
xecho $A
Result
%%(xml)
<foo>text</foo>
<bar>text</bar>
Sequences can be appended using the syntax
VAR+=value
This is a syntax shortcut for
VAR=($VAR,value)
or
VAR=<[ $VAR , value ]>
If the variable doesn't exist it is created as if assigned using =.
Example: Create a sequence of integers 1 to 10 then append 20 to 30
A=<[ 1 to 10 ]>
A+=<[ 20 to 30 ]>
echo $A
Result
1 2 3 4 5 6 7 8 9 10 20 21 22 23 24 25 26 27 28 29 30
Example Create an element then append to it
A=<[ <foo>text</foo> ]>
A+=<[ <bar>text</bar> ]>
xecho $A
Result
%%(xml)
<foo>text</foo>
<bar>text</bar>
Additions:
Note that this is different then non-sequence construction which doesn't do globbing (wildcard expansion).
Deletions:
Additions:
var=()
echo <[count($var)]>
returns
var=""
echo <[count($var)]>
Returns
====Array Notation====
xmlsh supports a simplified version of the bash array notation in variable expansion.
The expression ${variable[index]} expands to the index'd element of a sequence variable. Index starts at 1 for compatibility with xpath expressions. ${variable[index]} is equivalent to <[ $variable[index] ]>.
The expression ${#variable} expands to the sequence length of variable. ${#variable} is equivalent to <[ count($variable) ]>
A non-sequenced variable is equivalent to a sequenced variable of length 1.
Unlike bash, sparse arrays are not supported because array notation is just a syntactic simplification over the XML infoset sequence variables which cannot be sparse.
Examples
var=(foo bar spam)
echo ${#var}
echo ${var[2]}
returns
3
bar
var=<[ "foo" , <spam attr="bar"><bletch>text</bletch></spam> , 1 , 2 , 3 ]>
echo ${#var}
xecho ${var[2]}
returns
5
<spam attr="bar"><bletch>text</bletch></spam>
echo <[count($var)]>
returns
var=""
echo <[count($var)]>
Returns
====Array Notation====
xmlsh supports a simplified version of the bash array notation in variable expansion.
The expression ${variable[index]} expands to the index'd element of a sequence variable. Index starts at 1 for compatibility with xpath expressions. ${variable[index]} is equivalent to <[ $variable[index] ]>.
The expression ${#variable} expands to the sequence length of variable. ${#variable} is equivalent to <[ count($variable) ]>
A non-sequenced variable is equivalent to a sequenced variable of length 1.
Unlike bash, sparse arrays are not supported because array notation is just a syntactic simplification over the XML infoset sequence variables which cannot be sparse.
Examples
var=(foo bar spam)
echo ${#var}
echo ${var[2]}
returns
3
bar
var=<[ "foo" , <spam attr="bar"><bletch>text</bletch></spam> , 1 , 2 , 3 ]>
echo ${#var}
xecho ${var[2]}
returns
5
<spam attr="bar"><bletch>text</bletch></spam>
Deletions:
$ echo <[count($var)]>
$ var=""
$ echo <[count($var)]>
Additions:
Assuming there are 21 xml files in the current directory
$ echo <[ count($var) ]>
21
$ var=*.xml
$ echo <[ count($var) ]>
$ echo <[ count($var) ]>
21
$ var=*.xml
$ echo <[ count($var) ]>
Additions:
====Sequence Construction====
Variable assignment supports a simplified sequence expression, similar to bash and ksh array assignment.
var=(elem elem ...)
For example
$ var=(foo bar spam)
Assigns an XML sequence of strings equivilent to
$ var=<[("foo","bar","spam")]>
The values inside () are expanded using Word expansion and Globbing before being assigned.
Note that this is different then non-sequence construction which doesnt do globbing (wildcard expansion).
$ var=(*.xml)
Assigns var to be the sequence containing all xml files in the current directory.
The empty sequence construct creates an empty sequence. This is different then string assignment which creates a empty string.
$ var=()
$ echo <[count($var)]>
0
$ var=""
$ echo <[count($var)]>
1
Variable assignment supports a simplified sequence expression, similar to bash and ksh array assignment.
var=(elem elem ...)
For example
$ var=(foo bar spam)
Assigns an XML sequence of strings equivilent to
$ var=<[("foo","bar","spam")]>
The values inside () are expanded using Word expansion and Globbing before being assigned.
Note that this is different then non-sequence construction which doesnt do globbing (wildcard expansion).
$ var=(*.xml)
Assigns var to be the sequence containing all xml files in the current directory.
The empty sequence construct creates an empty sequence. This is different then string assignment which creates a empty string.
$ var=()
$ echo <[count($var)]>
0
$ var=""
$ echo <[count($var)]>
1
Additions:
Variables are created using variable assignment ([[Variables]]). The type of the expression determins
Deletions:
Additions:
----
See Also [[BasicSyntax]]
Additions:
E=$(ls)
A=$<(xls)
A=$<(xls)
Deletions:
Additions:
C=${B}
D=$(echo yet more strings)
D=$(echo yet more strings)
Deletions:
Additions:
DOC=<[<foo><bar>text</bar></foo>]>
T=<[<spam>{$DOC//bar}</spam>]>
T=<[<spam>{$DOC//bar}</spam>]>