Implicit Type Conversion
Release 1.0 - ...
SXML is strongly typed: it is aware of the difference between, for example, an integer and a string.
Whenever a type must be converted to another type, the rules listed in the table below are used to determine whether the type conversion can be applied automatically. To force a conversion between types that cannot be converted automatically, use one of the conversion vipers.
FROM | ||||||
---|---|---|---|---|---|---|
TO | boolean | integer | float | string | datetime | |
boolean | - | Y* | x | x | x | |
integer | x | - | x | x | x | |
float | x | Y | - | x | x | |
string | Y* | Y | Y | - | Y* | |
datetime | x | x | x | x | - |
Remarks
- Conversion from integer to bool: 0= false else true.
- Conversion from bool to string: 'true' or 'false'.
- Conversion of datetime to string: XML formatted string, for example '2007-12-05T12:34:56'
Examples of implicit type conversions:
Smartsite SXML | Copy Code |
---|---|
boolean to string: {sys.eval( 'string ' + (1==1) )} => 'string true' boolean to string: {sys.eval( 'string ' + (0==1) )} => 'string false' integer to string: {sys.eval( 'string ' + (1+2) )} => 'string 3' float to string: {sys.eval( 'string ' + convert.todate('2010-12-25T12:34:56') )} => 'string 2010-12-25T12:34:56' datetime to string: {sys.eval( 'string ' + 5.6789 )} => 'string 5.6789' integer to bool: {sys.eval( 0==false )}; => true integer to bool: {sys.eval( 1==true )}; => true integer to float: {sys.eval( 123 + 5.6789 )}; => 128.6789 |