docs.roxen.comBack to normal mode
DocsRoxenWebServer 5.0Web Developer ManualVariable Tags
Copyright © 2012, Roxen Internet Software
Suggestions, comments & compliments
manuals@roxen.com

<set/> or <set></set>

Provided by module: Tags: RXML tags

Sets a variable in any scope that isn't read-only.

Before: &var.language;<br /> <set variable="var.language">Pike</set> After: &var.language;<br />
Before:
After: Pike

Attributes

variable="string"

The name of the variable to set.


value="string"

The value the variable should have. This is an alternative to specifying the value in the content, and the content must be empty if this is used.

The difference is that the value always is parsed as text here. Even if a type is specified with the "type" attribute this is still parsed as text, and then converted to that type.


from="string"

Get the value from this variable. The content must be empty if this is used.


expr="string"

An expression that gets evaluated to produce the value for the variable. The content must be empty if this is used.

Expression values can take any of the following forms:

scope.var

The value of the given RXML variable. Note that it is not written as an entity reference; i.e. it is written without the surrounding "&" and ";".

49

A decimal integer.

0xFE, 0xfe

A hexadecimal integer is preceded by "0x".

040

An octal integer is preceded by "0".

0b10100110

A binary integer is preceded by "0b".

1.43, 1.6e-5

A floating point number contains "." and/or "E"/"e".

"hello"

A string inside double quotes. C-style backslash escapes can be used in the string, e.g. a double quote can be included using \".

(expr)

Parentheses can be used around an expression for grouping inside a larger expression.

Value conversion expressions:

(int) expr

Casts a numeric or string expression (containing a formatted number on one of the formats above) to an integer.

(float) expr

Casts a numeric or string expression (containing a formatted number on one of the formats above) to a floating point number.

(string) expr

Casts a numeric or string expression to a string. If it is an integer then it is formatted as a decimal number. If it is a floating point number then it is formatted on the form [-]XX[.XX][e[-]XX].

INT(expr), FLOAT(expr), STRING(expr)

These functions cast their arguments to integer, float, or string, respectively. They behave like the cast operators above except that they do not generate any error if expr cannot be cast successfully. Instead a zero number or an empty string is returned as appropriate. This is useful if expr is a value from the client that might be bogus.

Note that values in RXML variables often are strings even though they might appear as (formatted) numbers. It is therefore a good idea to use the INT() or FLOAT() functions on them before you do math.

Expressions for numeric operands:

expr1 * expr2

Multiplication.

expr1 / expr2

Division.

expr1 % expr2

Modulo.

expr1 + expr2

Addition.

expr1 - expr2

Subtraction.

expr1 < expr2

Less than.

expr1 > expr2

Greater than.

expr1 <= expr2

Less than or equal.

expr1 >= expr2

Greater than or equal.

expr1 & expr2

Bitwise AND (integer operands only).

expr1 ^ expr2

Bitwise XOR (integer operands only).

expr1 | expr2

Bitwise OR (integer operands only).

pow(expr1, expr2)

Returns the value expr1 raised to the power of expr2.

abs(expr)

Returns the absolute value of expr.

Expressions for string operands:

expr * num

Returns expr repeated num times.

expr1 / expr2

Returns an array with expr1 split on expr2. E.g. the string "a,b,c" split on "," is an array with the three elements "a", "b", and "c".

expr1 + expr2

Returns expr1 concatenated with expr2.

expr1 - expr2

Returns expr1 without any occurrences of expr2.

sizeof(expr)

Returns the number of characters in expr.

search(expr1, expr2)

Returns the starting position of the first occurrence of the substring expr2 inside expr1, counting from 1, or 0 if expr2 does not occur in expr1.

reverse(expr)

Returns the reverse of expr.

Expressions for array operands:

expr * num

Returns expr repeated num times.

expr1 + expr2

Returns expr1 concatenated with expr2.

expr1 - expr2

Returns expr1 without any of the elements in expr2.

expr1 & expr2

Returns the elements that exist in both expr1 and expr2, ordered according to expr1.

expr1 ^ expr2

Returns the elements that exist in either expr1 or expr2 but not in both. The order is expr1 followed by expr2.

expr1 | expr2

Returns the elements that exist in either expr1 or expr2. The order is expr1 followed by expr2. (The difference from expr1 + expr2 is that elements in expr2 aren't repeated if they occur in expr1.)

sizeof(expr)

Returns the number of elements in expr.

search(arr, expr)

Returns the position of the first occurrence of the element expr inside the array arr, counting from 1, or 0 if expr does not exist in arr.

reverse(expr)

Returns the reverse of expr.

uniq(expr)

Returns expr with all duplicate elements removed. The order among the remaining elements is kept intact; it is always the first of several duplicate elements that is retained.

Expressions for all types of operands:

!expr

Logical negation: 1 (true) if expr is the integer 0 (zero), otherwise 0 (false).

expr1 == expr2

1 (true) if expr1 and expr2 are the same, 0 (false) otherwise. Note that arrays might be different even though they contain the same sequence of elements.

expr1 != expr2

1 (true) if expr1 and expr2 are different, 0 (false) otherwise. This is the inverse of the == operator.

equal(expr1, expr2)

1 (true) if expr1 and expr2 are structurally equal, 0 (false) otherwise. As opposed to the == operator above, this returns 1 if two arrays contain the same sequence of elements.

expr1 && expr2

Nonzero (true) if both expressions are nonzero (true), 0 (false) otherwise. A true return value is actually the value of expr2.

expr1 || expr2

Nonzero (true) if either expression is nonzero (true), 0 (false) otherwise. A true return value is actually the value of the last true expression.


type="type"

The type of the value. If the value is taken from the content then this is the context type while evaluating it. If "value", "from" or "expr" is used then the value is converted to this type. Defaults to "any".

Tip: The <value> tag is useful to construct nonstring values, such as arrays and mappings:

<set variable="var.x" type="array"> <value>alpha</value> <value>beta</value> </set> &var.x;
Array result: ({"alpha", "beta"})

split="string"

Split the value on this string to form an array which is set. The value gets converted to a string if it isn't one already.

<set variable="var.x" split=",">a,b,c</set> &var.x;
Array result: ({"a", "b", "c"})