Building Queries and Data Views
|
Constructor Functions
Constructor functions process a source value as the argument. Every data element or variable has a data type. The data type determines the value that any function parameter can contain and the operations that can be performed on it. The Liquid Data supports the following type casting functions. The following constructor functions are available:
xf:boolean-from-string
Returns a boolean value of true or false from the string source value.
Data Types
- Input data type: xs:string?
- Returned data type: xs:boolean?
Notes
If the input parameter is empty, the function returns an empty list. Otherwise, Liquid Data generates an error.
XQuery Specification Compliance
- Conforms to the current specification; however, Liquid Data does not accept the values "1" and "0" to represent true and false, as described in the W3C XML Schema document.
Examples
- xf:boolean-from-string("true") returns the boolean value true.
- xf:boolean-from-string("FaLSe") returns the boolean value false.
- xf:boolean-from-string("43") generates a runtime error because the input value cannot be parsed into a boolean value.
- xf:boolean-from-string(43) generates a compile-time error because the input value is not a string.
xf:byte
Constructs a byte integer value from the string source value.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:byte?
Notes
An error occurs if the source value is greater than 127 or less than -128.
Liquid Data truncates the input if it is a non-integer number.
If the number falls outside of the range of byte values, the number wraps.
If the number is an integer that falls within the range, the value is unchanged.
If the input is a string, Liquid Data tries to parse it into a byte value.
If the input is the boolean value true, the function returns 1. If it is false, it returns 0.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN) or -0.
- Liquid Data attempts to support any input value and convert it at run time.
Examples
- xf:byte('127') returns the byte value one hundred twenty seven.
- xf:byte(38) returns the byte value 38.
- xf:byte("-4") returns the byte value -4.
- xf:byte(128) returns the byte value -128 because the number wraps.
- xf:byte(-129) returns the byte value 127 because the number wraps.
- xf:byte(xf:true()) returns the byte value 1.
- xf:byte(xf:false()) returns the byte value 0.
- xf:byte("true") generates a runtime error because the string literal cannot be converted to a byte value.
- xf:byte('128') returns an error because one hundred twenty eight is invalid for a byte integer expression.
xf:decimal
Constructs a decimal value from the source value.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:decimal?
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
- Liquid Data supports "e" and "E" to construct floating point integer values.
Examples
- xf:decimal("3") returns the decimal value 3.
- xf:decimal(99.1) returns the decimal value 99.1 (the same value that is input to the function).
- xf:decimal(xf:true()) returns the decimal value 1.
- xf:decimal(xf:false()) returns the decimal value 0.
- xf:decimal("true") generates a runtime error because the string literal cannot be converted to a decimal value.
xf:double
Constructs a double precision value from the source value.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:double?
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- xf:double("3") returns the double precision floating point value 3.0.
- xf:double(5.1) returns the double precision floating point value 5.1.
- xf:double(xf:true()) returns the double precision floating point value 1.0.
- xf:double(xf:false()) returns the double precision floating point value 0.0.
- xf:double("true") generates a runtime error because the string literal cannot be converted to a double precision floating point value.
- xf:double("12345678901234567890") evaluates to the double precision floating point value 1.2345678901234567E19.
xf:float
Constructs a floating point value from the source value.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:float?
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- xf:float(1) returns the floating-point value 1.0.
- xf:float("1") returns the floating-point value 1.0.
- xf:float(xf:true()) returns the floating point value 1.0.
- xf:float(xf:false()) returns the floating-point value 0.0.
- xf:float("true") generates a runtime error because the string literal cannot be converted to a floating-point value.
- xf:float("12345678901234567890") returns the floating-point value 1.2345679E19.
xf:int
Constructs an integer value from the source value. The largest integer value is limited to a 32-bit expression.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:integer?
Notes
An error occurs if the source value is greater than 2,147,483,647 or less than -2,147,483,648. To the Liquid Data Server, the xf:int function is exactly the same as the xf:integer function.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN) or -0.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- xf:int(4056) returns the int value 4056.
- xf:int("-35") returns the int value -35.
- xf:int(xf:true()) returns the int value 1.
- xf:int(xf:false()) returns the int value 0.
- xf:int("true") generates a runtime error because the string literal cannot be converted to an int value.
xf:integer
Constructs an integer value from the source value. The largest integer value is limited to a 32-bit expression.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:integer?
Notes
An error occurs if the source value is greater than 2,147,483,647 or less than -2,147,483,648. To the Liquid Data Server, the xf:integer function is exactly the same as the xf:int function.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN), -0, or the negative and positive infinity values -INF and INF.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- xf:integer(4056) returns the int value 4056.
- xf:integer("-35") returns the int value -35.
- xf:integer(xf:true()) returns the int value 1.
- xf:integer(xf:false()) returns the int value 0.
- xf:integer("true") generates a runtime error because the string literal cannot be converted to an int value.
xf:long
Constructs a four-byte integer value from the source value. Use a long integer data type when the value exceeds the limitations imposed by other integer data types.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:long?
Notes
An error occurs if the source value is greater than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN) or -0.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- xf:long(1) returns the long integer value 1.
- xf:long("-91") returns the long integer value -91.
- xf:long(xf:true()) returns the long integer value 1.
- xf:long(xf:false()) returns the long integer value 0.
- xf:long("true") generates a runtime error because the string literal cannot be converted to a long integer value.
xf:short
Constructs a two-byte integer value from the source value. The largest short integer value is limited to a 16-bit expression.
Data Types
- Input data type: xsext:anyValue?
- Returned data type: xs:short?
Notes
An error occurs if the source value is greater than 32,767 or less than -32,768.
XQuery Specification Compliance
- Liquid Data does not support not-a-number (NaN) or -0.
- Liquid Data attempts to support any input value, instead of just string literals, and convert it at run time.
Examples
- xf:short(1) returns the short integer value 1.
- xf:short("-91") returns the short integer value -91.
- xf:short(xf:true()) returns the short integer value 1.
- xf:short(xf:false()) returns the short integer value 0.
- xf:short("true") generates an error because the string literal cannot be converted to a short integer value.
xf:string
Constructs a string value from the source value. The source value can be a sequence, a node of any kind, or a simple value.
Data Types
- Input data type: xs:anyType
- Returned data type: xs:string?
Notes
Liquid Data accepts any simple value, but supports no other accessor types, such as a sequence or other type of node.
XQuery Specification Compliance
- Liquid Data treats xf:string as both a constructor and an accessor.
- Liquid Data supports only the string format that requires one node of any type as the input.
- Liquid Data accepts xsext:anyType input instead of a list of items.
- Liquid Data returns an optional string.
- Liquid Data does not recognize entities.
Examples
- xf:string(1) returns the string value "1."
- xf:string("-91") returns the string value "-91."
- xf:string(xf:true()) returns the string value "true."
- xf:string(xf:false()) returns the string value "false."
- xf:string("abc", "def") generates a compile-time error because the function does not accept two parameters.
- xf:string(("abc", "def")) generates a compile-time error because the function does not accept a sequence as parameter.
- xf:string(<a/>) returns an empty string value "".
- xf:string(<a>abc</a>) returns the string value "abc."