XQuery Reference

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

XQuery Type Conversion Functions Reference

This chapter provides descriptions of the XQuery type conversion functions available in the mapper functionality of WebLogic Workshop. You use the mapper functionality to generate queries and to edit these queries to add invocations to these provided XQuery functions. To learn more, see Invoking Functions or Operators in a Query.

In addition to the XQuery functions available in the mapper functionality of WebLogic Workshop, a larger set functions is provided. You can manually add invocations to these functions to queries in the Source View of the mapper functionality. For a list of these additional functions, see the XQuery 1.0 and XPath 2.0 Functions and Operators - W3C Working Draft 16 August 2002 available from the W3C Web site at the following URL:

http://www.w3.org/TR/2002/WD-xquery-operators-20020816

This section lists the type conversion functions available from the mapper functionality:

 


xs: string

Converts the value of $item-var to a string.

If $item-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:string(item* $item-var) —>xs: string

Table 4-1 Arguments
Data Type
Argument
Description
item*
$item-var
Represents an atomic value or an element.

Returns

Returns the representation of $item-var as a string.

Examples
XML Node

When you invoke the following query:

{-- node example --}

let $i := <book>The Toad</book>

return <author>{xs:string($i)}</author>

The following result is generated:

<author>The Toad</author>

Integer

When you invoke the following query:

{-- integer example --}

let $num := xs:integer("20")

return (<integer>{xs:string($num)}</integer>)

The following result is generated:

<integer>20</integer>

Float

When you invoke the following query:

{-- float example --}

let $num := xs:float("44.4")

return (<float>{xs:string($num)}</float>)

The following result is generated:

<float>44.4</float>

Boolean

When you invoke the following query:

{-- boolean example --}

let $boolean-var := xs:boolean("true")

return (<boolean>{xs:string($boolean-var)}</boolean>)

The following result is generated:

<boolean>true</boolean>

Related Topics

W3C string function description

 


xs: decimal

Converts $string-var (a string) to a decimal value.

If $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:decimal(xs: string $string-var) —> xs: decimal

Table 4-2 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents the string to convert to a decimal number.

Returns

Returns the decimal value of $string-var

Examples
Simple

Invoking decimal("2.2") returns the decimal value 2.2 as shown in the following example query:

<decimal>{xs:decimal("2.2")}</decimal>

The preceding query generates the following result:

<decimal>2.2</decimal>

Null

Invoking decimal(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<decimal>{xs:decimal(())}</decimal>

The preceding query generates the following result:

<decimal/>

Related Topics

W3C decimal data type description

 


xs: integer

Converts $string-var (a string) to an integer value.

If the value of $string-var is greater than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808, the TransformException exception is raised with the SYS_LONG_OVERFLOW fault code. The following error message is displayed in the mapper:

Error occurred while executing XQuery: BigDecimal -> Long overflow!

Note: For performance reasons, the integer supported by this XQuery engine is equivalent to a Java long, which is smaller than the W3C XML Schema integer, which has an arbitrary length. To learn more, see the integer description.
Note: The value $string-var must be specified without commas as shown in the following example invocation:

xs:integer("999999999")

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:integer(xs: string $string-var) —> xs: integer

Table 4-3 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents the string to convert to an integer value

Returns

Returns an integer value of $string-var

Examples
Simple

Invoking integer("10402") returns the integer value 10402 as shown in the following example query:

<integer>{xs:integer("10402")}</integer>

The preceding query generates the following result:

<integer>10402</integer>

Error—Decimal Point is Not Allowed

Invoking integer("104.0") outputs an error because the decimal point is not allowed in the argument.

For example, the following example query:

<integer>{xs:integer("104.0")}</integer>

Produces the following error:

Error occurred while executing XQuery: Could not cast "104.0" to type [integer@http://www.w3.org/2001/XMLSchema]

Error—Not a Number

Invoking integer("foo") outputs an error because "foo" is not a number.

For example, the following example query:

<integer>{xs:decimal("foo")}</integer>

Produces the following error:

Error occurred while executing XQuery: Could not cast "foo" to type [integer@http://www.w3.org/2001/XMLSchema]

Null

Invoking integer(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<integer>{xs:integer(())}</integer>

The preceding query generates the following result:

<integer/>

XQuery Compliance

An integer value in this XQuery engine has a maximum size of 9,223,372,036,854,775,807 and a minimum size of -9,223,372,036,854,775,808. For performance reasons, the integer supported by this XQuery engine is equivalent to a Java long, which is smaller then the W3C XML Schema integer, which has an arbitrary length.

Related Topics

integer data type description

Getting the TransformException Fault Code Programmatically

 


xs: long

Converts $string-var (a string) to a long value.

If the value of $string-var is greater than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808, the following error message is displayed:

Error occurred while executing XQuery: Could not cast "9223372036854775809" to type [long@http://www.w3.org/2001/XMLSchema]

Note: The value $string-var must be specified without commas as shown in the following example invocation:

xs:long("999999999")

If $string-var is the empty sequence, the empty sequence is returned.

The empty sequence is a sequence containing zero items(), which is similar to null in SQL.s

Signatures

xs:long(xs: string $string-var) —> xs: long

Table 4-4 Arguments
Data Type
Argument
Description
xs: string
string-var
Represents the string to convert to long value.

Returns

Returns the long value of $string-var.

Examples
Simple

Invoking long("10403") returns the integer value 10403 as shown in the following example query:

<long>{xs:long("10403")}</long>

The preceding query generates the following result:

<long>10403</long>

Error—Decimal Point Not Allowed

Invoking long("104.0") outputs an error because 104.0 is not a valid integer (decimal point is not allowed.)

For example, the following example query:

<long>{xs:long("104.0")}</long>

Produces the following error:

Error occurred while executing XQuery: Could not cast "104.0" to type [long@http://www.w3.org/2001/XMLSchema]

Error—Not a Number

Invoking long("foo") outputs an error because "foo" is not a number.

For example, the following example query:

<long>{xs:long("foo")}</long>

Produces the following error:

Error occurred while executing XQuery: Could not cast "foo" to type [long@http://www.w3.org/2001/XMLSchema]

Null

Invoking long(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<long>{xs:long(())}</long>

The preceding query generates the following result:

<long/>

Related Topics

W3C long data type description

 


xs: int

Converts $string-var (a string) to an int value.

If the value of $string-var is greater than 2,147,483,647 or less than -2,147,483,648, the following error is produced:

Error occurred while executing XQuery: Could not cast "2147483649" to type [int@http://www.w3.org/2001/XMLSchema]

Note: The value $string-var must be specified without commas as shown in the following example invocation:

xs:int("999999999")

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in sSQL.

Signatures

xs:int(xs: string $string-var) —>xs: int

Table 4-5 Arguments
Data Type
Argument
Description
XS:String
$string-var
Represents the string to convert to an int value

Returns

Returns the int value of $string-var.

Examples
Simple

Invoking int("10403") returns the integer value 10403 as shown in the following example query:

<int>{xs:int("10403")}</int>

The preceding query generates the following result:

<int>10403</int>

Error—Decimal Point Not Allowed

Invoking int("104.0") outputs an error because 104.0 not a valid integer (decimal point is not allowed.)

For example, the following example query:

<int>{xs:int("104.0")}</int>

Produces the following error:

Error occurred while executing XQuery: Could not cast "104.0" to type [int@http://www.w3.org/2001/XMLSchema]

Error—Not a Number

Invoking int("foo") outputs an error because "foo" is not a number.

For example, the following example query:

<int>{xs:int("foo")}</int>

Produces the following error:

Error occurred while executing XQuery: Could not cast "foo" to type [int@http://www.w3.org/2001/XMLSchema]

Null

Invoking int(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<int>{xs:int(())}</int>

The preceding query generates the following result:

<int/>

Related Topics

W3C int data type description

 


xs: short

Converts $string-var (a string) to a short value.

If the value of $string-var is greater than 32,767 or less than -32,768, the following error is produced:

Error occurred while executing XQuery: Could not cast "32769" to type [short@http://www.w3.org/2001/XMLSchema]

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:short(xs: string $string-var) —>xs: short

Table 4-6 Arguments
Data Type
Argument
Description
XS: String
$string-var
Represents the string to convert to a short value

Returns

Returns the short value of $string-var.

Examples
Simple

Invoking short("10403")returns the integer value 10403 as shown in the following example query:

<short>{xs:short("10403")}</short>

The preceding query generates the following result:

<short>10403</short>

Error—Decimal Point Not Allowed

Invoking short("104.0") outputs the an error because 104.0 is not a valid integer (decimal point is not allowed.)

For example, the following example query:

<short>{xs:short("104.0")}</short>

Produces the following error:

Error occurred while executing XQuery: Could not cast "104.0" to type [short@http://www.w3.org/2001/XMLSchema]

Error—Not a Number

Invoking short("foo")outputs an error because "foo" is not a number.

For example, the following example query:

<short>{xs:short("foo")}</short>

Produces the following error:

Error occurred while executing XQuery: Could not cast "foo" to type [short@http://www.w3.org/2001/XMLSchema]

Null

Invoking short(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<short>{xs:short(())}</short>

The preceding query generates the following result:

<short/>

Related Topics

W3C short data type description

 


xs: byte

Converts $string-var (a string) to a byte value.

If the value of $string-var is greater than 127 or less than -128, the following error is produced:

Error occurred while executing XQuery: Could not cast "129" to type [byte@http://www.w3.org/2001/XMLSchema]

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:byte(xs: string $string-var) —>xs: byte

Table 4-7 Arguments
Data Type
Argument
Description
xs: byte
$string-var
Represents the string to convert to a byte.

Returns

Returns the byte value of $string-var.

Examples
Simple

Invoking byte("104")returns the integer value 104 as shown in the following example query:

<byte>{xs:byte("104")}</byte>

The preceding query generates the following result:

<byte>104</byte>

Error—Decimal Point Not Allowed

Invoking byte("104.0") outputs an error because 104.0 is not a valid integer (decimal point is not allowed.)

For example, the following example query:

<byte>{xs:byte("104.0")}</byte>

Produces the following error:

Error occurred while executing XQuery: Could not cast "104.0" to type [byte@http://www.w3.org/2001/XMLSchema]

Error—Not a Number

Invoking byte("foo") outputs an error because "foo" is not a number.

For example, the following example query:

<byte>{xs:byte("foo")}</byte>

Produces the following error:

Error occurred while executing XQuery: Could not cast "foo" to type [byte@http://www.w3.org/2001/XMLSchema]

Null

Invoking byte(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<byte>{xs:byte(())}</byte>

The preceding query generates the following result:

<byte/>

Related Topics

W3C byte data type description.

 


xs: float

Converts $string-var (a string) to a 32 bit floating point value. The data type float corresponds to the IEEE single-precision 32-bit floating point type (IEEE Std 754-1985).

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:float(xs: string $string-var) —>xs: float

Table 4-8 Arguments
Data Type
Arguments
Description
xs: string
$string-var
Represents the string to convert to a float

Returns

Returns the floating point value of $string-var.

Examples
Simple

Invoking float("1.1")returns the floating point value of 1.1 as shown in the following example query:

<float>{xs:float("1.1")}</float>

The preceding query generates the following result:

<float>1.1</float>

Exponent

Invoking float("-104.345e2")returns the floating point value of -10434.5 as shown in the following example query:

<float>{xs:float("-104.345e2")}</float>

The preceding query generates the following error:

<float>-10434.5</float>

NaN

The string: NaN (Not a Number) is a legal argument, as shown in the following example query:

<float>{xs:float("NaN")}</float>

The preceding query generates the following result:

<float>NaN</float>

INF and -INF

The strings: INF (positive infinity) and -INF (negative infinity) are legal arguments as shown in the following example query:

<infinity>

<positive>{xs:float("INF")}</positive>

<negative>{xs:float("-INF")}</negative>

</infinity>

The preceding query generates the following result:

<infinity>

<positive>Infinity</positive>

<negative>-Infinity</negative>

</infinity>

Error—Invalid Exponent

Invoking float("10.1e2.1") outputs an error because 2.1 is not an integer. For example, the following example query:

<float>{xs:float("10.1e2.1")}</float>

Produces the following error:

Error occurred while executing XQuery: Could not cast "10.1e2.1" to type [float@http://www.w3.org/2001/XMLSchema]

Null

Invoking float(()) returns the empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

<float>{xs:float(())}</float>

The preceding query generates the following result:

<float/>

Related Topics

W3C float data type description

 


xs: double

Converts $string-var (a string) to a double precision (64 bit) floating point value.

The data type double corresponds to IEEE double-precision 64-bit floating point type ( IEEE 754-1985).

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:double(xs: string $string-var) —> xs: double

Table 4-9 Arguments
Data Type
Argument
Description
xs: string
$string-var
Represents the string to convert to a double.

Returns

Returns the double precision floating point value of $string-var.

Examples
Simple

Invoking double("1.1")returns the double precision floating point value of 1.1 as shown in the following example query:

<double>{xs:double("1.1")}</double>

The preceding query generates the following result:

<double>1.1</double>

Exponent

Invoking double("-104.345e2")returns the double floating point value of -10434.5 as shown in the following example query:

<double>{xs:double("-104.345e2")}</double>

The preceding query generates the following result:

<double>-10434.5</double>

NaN

The string: NaN (Not a Number) is a legal argument, as shown in the following example query:

<double>{xs:double("NaN")}</double>

The preceding query generates the following result:

<double>NaN</double>

INF and -INF

The strings: INF (positive infinity) and -INF (negative infinity) are legal arguments as shown in the following example query:

<infinity>

<positive>{xs:double("INF")}</positive>

<negative>{xs:double("-INF")}</negative>

</infinity>

The preceding query generates the following result:

<infinity>

<positive>Infinity</positive>

<negative>-Infinity</negative>

</infinity>

Error—Invalid Exponent

Invoking double("10.1e2.1") outputs an error because 2.1 is not an integer. For example, the following example query:

<double>{xs:double("10.1e2.1")}</double>

Produces the following error:

Error occurred while executing XQuery: Could not cast "10.1e2.1" to type [double@http://www.w3.org/2001/XMLSchema]

Error—Null

Invoking double(()) returns the empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL

For example, the following example query:

<double>{xs:double(())}</double>

The preceding query generates the following result:

<double/>

Related Topics

W3C double data type description

 


xf: number

Converts the value of $node-var (XML element) to a double precision floating point value.

Signatures

xf:number(xf: node $node-var) —> xs: double

Table 4-10 Arguments
Data Type
Argument
Description
xf:node
$node-var
Represents an XML node.

Returns

Returns the double precision floating point value of $node-var.

Examples
XML Node

When you invoke the following query:

{-- node example --}

let $numnode := <a><b>12.1</b></a>

return (<num>{xf:number($numnode/b)}</num>)

The following result is generated:

<num>12.1</num>

Related Topics

W3C number function description

 


bea-xf: integer-sequence

Converts a sequence of XML nodes into a sequence of integers. This function is usually used in conjunction with the xf: max and xf: min functions.

Signatures

bea-xf:: integer-sequence(node*$node-var) —> xs:integer*

Table 4-11 Arguments
Data Type
Argument
Description
node*
$node-var
Represents a sequence of XML nodes.

Returns

Returns a sequence of integers converted from XML nodes.

Examples
Simple

Invoking the following query returns a sequence of integers, as shown in the following example query:

let $x := <a>100</a>

let $y := <b>2</b>

let $z := <c>50</c>

return <result>{bea-xf:integer-sequence(($x,$y,$z))}</result>

The preceding query generates the following result:

<result>100 2 50</result>

 


xs: boolean

Converts a $string-var (a string) to a boolean value.

Signatures

xs:boolean(xs: string $string-var)—> xs: boolean

Table 4-12 Arguments
Data Type
Argument
Description
xs: string
$string-var
Represents the string to convert to a boolean value

Returns

Returns the boolean value of the passed in string.

Examples
Simple

Invoking xs:boolean("false") returns the boolean value false, as shown in the following example query:

<result>{xs:boolean("false")}</result>

The preceding query generates the following result:

<result>false</result>

Numeric

Invoking xs:boolean("1") returns the boolean value true, as shown in the following example query:

<result>{xs:boolean("1")}</result>

The preceding query generates the following result:

<result>true</result>

Related Topics

W3C boolean function description

 


xs: dateTime

Converts $string-var (a string in the dateTime format) to the dateTime data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the dateTime format the following error is reported:

Could not cast "invalid_dateTime_string" to type [date@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_dateTime_string is the string not valid to the date format, for example: "2003-08-16T21:10".

Signatures

xs: dateTime(xs: string $string-var) —> xs: dateTime

Table 4-13 Arguments 
Data Type
Argument
Description
xs:string
$string-var
Represents a string with the date and time specified with one of the following formats:
  • YYYY-MM-DDThh:mm:ss.sssssss
  • YYYY-MM-DDThh:mm:ss.sssssssZ
  • YYYY-MM-DDThh:mm:ss.sssssss+hh:mm
  • YYYY-MM-DDThh:mm:ss.sssssss-hh:mm
 
YYYY
Year.
MM
Month (as a number).
DD
Day.
T
Date and Time separator.
hh
Number of hours.
mm
Number of minutes.
ss.sssssss
Number of seconds.
Seconds can be specified up to 7 digits after the decimal place. (Format xx.xxxxxxx)
:
Separator between hours, minutes, or seconds.
+
Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed.
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC
mm
Number of minutes that the time zone differs from UTC
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified date and time in the dateTime data type.

Examples
Simple

Invoking dateTime("2003-08-16T21:10:50") returns a date Time value corresponding to August 16th, 2003 at 9:10PM (21:10 in twenty four hour time) and 50 seconds in the current time zone, as shown in the following example query:

let $mydate := xs:dateTime("2003-08-16T21:10:50")

return

<components>

<year>{xf:get-year-from-dateTime($mydate)}</year>

<month>{xf:get-month-from-dateTime($mydate)}</month>

<day>{xf:get-day-from-dateTime($mydate)}</day>

<hour>{xf:get-hours-from-dateTime($mydate)}</hour>

<minute>{xf:get-minutes-from-dateTime($mydate)}</minute>

<second>{xf:get-seconds-from-dateTime($mydate)}</second>

</components>

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

<hour>21</hour>

<minute>10</minute>

<second>50</second>

</components>

Seconds with Decimal

Invoking dateTime("2003-08-16T21:10:50.577") returns a date Time value corresponding to August 16th, 2003 at 9:10 PM (21:10 in twenty four hour time) and 50.577 seconds in the current time zone, as shown in the following example query:

let $mydate := xs:dateTime("2003-08-16T21:10:50.557")

return

<components>

<year>{xf:get-year-from-dateTime($mydate)}</year>

<month>{xf:get-month-from-dateTime($mydate)}</month>

<day>{xf:get-day-from-dateTime($mydate)}</day>

<hour>{xf:get-hours-from-dateTime($mydate)}</hour>

<minute>{xf:get-minutes-from-dateTime($mydate)}</minute>

<second>{xf:get-seconds-from-dateTime($mydate)}</second>

</components>

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

<hour>21</hour>

<minute>10</minute>

<second>50.5570000</second>

</components>

UTC Time Zone

Invoking dateTime("2003-08-16T21:10:50Z") returns a date Time value corresponding to August 16th, 2003 at 9:10 PM (21:10 in twenty four hour time) and 50 seconds, in the UTC time zone, as shown in the following example query:

let $mydate := xs:dateTime("2003-08-16T21:10:50Z")

return

<components>

<year>{xf:get-year-from-dateTime($mydate)}</year>

<month>{xf:get-month-from-dateTime($mydate)}</month>

<day>{xf:get-day-from-dateTime($mydate)}</day>

<hour>{xf:get-hours-from-dateTime($mydate)}</hour>

<minute>{xf:get-minutes-from-dateTime($mydate)}</minute>

<second>{xf:get-seconds-from-dateTime($mydate)}</second>

</components>

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

<hour>21</hour>

<minute>10</minute>

<second>50</second>

</components>

Offset Time Zone

Invoking dateTime("2003-08-16T13:10:50-07:00") returns a date Time value corresponding to August 16th, 2003 at 1:10 PM (13:10 in twenty four hour time) and 50 seconds, in the Pacific Daylight Savings (PDT) time zone that is offset by -7 hours from UTC (Universal Time, Coordinated), as shown in the following example query:

let $mydate := xs:dateTime("2003-08-16T13:10:50-07:00")

return

<components>

<year>{xf:get-year-from-dateTime($mydate)}</year>

<month>{xf:get-month-from-dateTime($mydate)}</month>

<day>{xf:get-day-from-dateTime($mydate)}</day>

<hour>{xf:get-hours-from-dateTime($mydate)}</hour>

<minute>{xf:get-minutes-from-dateTime($mydate)}</minute>

<second>{xf:get-seconds-from-dateTime($mydate)}</second>

</components>

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

<hour>20</hour>

<minute>10</minute>

<second>50</second>

</components>

The conversion of the date and time is shown in the following figure

Figure 4-1 Date and Time Conversion

Date and Time Conversion

Error—No Seconds

Invoking dateTime("2003-08-16T21:10") outputs an error because seconds are not specified.

For example, the following example query:

<result>{xs:dateTime("2003-08-16T21:10")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "2003-08-16T21:10" to type [dateTime@http://www.w3.org/2001/XMLSchema]

Error—Incorrect Format

Invoking dateTime("2003-8-16T21:10:50") outputs an error because the month is not specified using two digits.

For example, the following example query:

<result>{xs:dateTime("2003-8-16T21:10:50")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "2003-8-16T21:10:50" to type [dateTime@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C dateTime data type description

 


xs: date

Converts $string-var (a string in the date format) to the date data type.

If the value of $string-var is the empty sequence, the empty sequence is returned.The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the date format the following error is reported:

Could not cast "invalid_date_string" to type [date@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_date_string is the string not valid to the date format, for example: "2003-04-31".

Signatures

xs:date(xs: string $string-var)—> xs: date

Table 4-14 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents a string with the date specified with one of the following formats:

YYYY-MM-DD

YYYY-MM-DDZ

YYYY-MM-DD+hh:mm

YYYY-MM-DD-hh:mm

 

YYYY

Year.

MM

Month (as a number).

DD

Day.

-

Separator between year, month, and day.

hh

Number of hours.

mm

Number of minutes.

:

Separator between hours and minutes.

+

Positive time zone offset (If a plus or minus is not specified, + is assumed.)

-

Negative time zone offset

hh

Number of hours that the time zone differs from UTC.

mm

Number of minutes that the time zone differs from UTC.

Z

Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified date in the date data type.

Examples
Simple

Invoking date("2003-08-16")returns a date value corresponding to August 16th, 2003 in the current time zone, as shown in the following example query:

let $mydate := xs:date("2003-08-16")

return

<components>

<year>{xf:get-year-from-date($mydate)}</year>

<month>{xf:get-month-from-date($mydate)}</month>

<day>{xf:get-day-from-date($mydate)}</day>

</components>

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

</components>

UTC Time Zone

Invoking date("2003-08-16Z") returns a date value corresponding to August 16th, 2003 in the UTC time zone, as shown in the following example query:

let $mydate := xs:date("2003-08-16Z")

return

<components>

<year>{xf:get-year-from-date($mydate)}</year>

<month>{xf:get-month-from-date($mydate)}</month>

<day>{xf:get-day-from-date($mydate)}</day>

</components>

Note: The Z in the a date string, specifies that the date is specified in the UTC time zone.

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

</components>s

Offset Time Zone

Invoking date("2003-08-16-02:00") returns a date value corresponding to August 16th, 2003 in a time zone that is offset by -2 hours from UTC, as shown in the following example query:

let $mydate := xs:date("2003-08-16-02:00")

return

<components>

<year>{xf:get-year-from-date($mydate)}</year>

<month>{xf:get-month-from-date($mydate)}</month>

<day>{xf:get-day-from-date($mydate)}</day>

</components>

The preceding query, generates the following XML result:

<components>

<year>2003</year>

<month>8</month>

<day>16</day>

</components>

Error—Not A Valid Date

Invoking date("2003-04-31") outputs an error because April 31, 2003 is not a valid date. (There is no 31 day in April.)

For example, the following example query:

<result>{xs:date("2003-04-31")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "2003-04-31" to type [date@http://www.w3.org/2001/XMLSchema]

Error—Incorrect Format

Invoking date("2003-8-16") outputs an error because the month is not specified using two digits.

For example, the following example query:

<result>{xs:date("2003-8-16")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "2003-8-16" to type [date@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C date data type description

 


xs:time

Converts $string-var (a string in the time format) to the time data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the time format the following error is reported:

Could not cast "invalid_time_string" to type [time@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_time_string is the string not valid to the time format, for example: "23:5:44".

Signatures

xs:time(xs: string $string-var)—>xs: time

Table 4-15 Arguments  
Data Type
Argument
Description
 
xs:string
$string-var
Represents a string with the time specified with one of the following formats
  • hh:mm:ss.sssssss
  • hh:mm:ss.sssssssZ
  • hh:mm:ss+hh:mm
  • hh:mm:ss-hh:mm
 
YYYY
Year.
MM
Month (as a number).
DD
Day.
hh
Number of hours.
mm
Number of minutes.
ss.sssssss

Number of seconds.

Seconds can be specified up to 7 digits after the decimal place. (Format xx.xxxxxxx)
:
Separator between hours, minutes and seconds.
+
Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC.
mm
Number of minutes that the time zone differs from UTC.
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified time in the time data type.

Examples
Simple

Invoking time("23:15:45") returns a time value corresponding to 11:15 PM and 45 seconds in the current time zone, as shown in the following example query:

let $mytime := xs:time("23:15:45")

return

<components>

<hours>{xf:get-hours-from-time($mytime)}</hours>

<minutes>{xf:get-minutes-from-time($mytime)}</minutes>

<seconds>{xf:get-seconds-from-time($mytime)}</seconds>

</components>

The preceding query, generates the following XML result:

<components>

<hours>23</hours>

<minutes>15</minutes>

<seconds>45</seconds>

</components>

UTC Time Zone

Invoking time("23:15:45Z") returns a time value corresponding to 11:15 PM and 45 seconds in the UTC time zone, as shown in the following example query:

let $mytime := xs:time("23:15:45Z")

return

<components>

<hours>{xf:get-hours-from-time($mytime)}</hours>

<minutes>{xf:get-minutes-from-time($mytime)}</minutes>

<seconds>{xf:get-seconds-from-time($mytime)}</seconds>

</components>

The preceding query, generates the following XML result:

<components>

<hours>23</hours>

<minutes>15</minutes>

<seconds>45</seconds>

</components>

Error—Incorrect Format

Invoking time("23:5:44") outputs an error because the minutes is not specified using two digits.

For example, the following example query:

<result>{xs:time("23:5:44")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "23:5:44" to type [time@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C time data type description

 


xs: gYearMonth

Converts $string-var (a string in the gYearMonth format) to the gYearMonth data type.

If the value of $string-var is the empty sequence, the empty sequence is returned.The empty sequence is a sequence containing zero items(), which is similar to null in SQL.

If the value of $string-var is not valid to the gYearMonth format, the following error is reported:

Could not cast "invalid_gYearMonth_string" to type [gYearMonth@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_gYearMonth_string is the string not valid to the time format, for example: "2003-8".

Signatures

xs:gYearMonth(xs: string $string-var)—> xs: gYearMonth

Table 4-16 Arguments
Data Type
Argument
Description
xs:string
$string-var

Represents a string with the month and year specified with one of the following formats:

YYYY-MM
YYYY-MMZ
YYYY-MM+hh:mm
YYYY-MM-hh:mm
 
YYYY
Year.
-
Separator between year and months.
MM
Month (as a number).
+
Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed.
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC.
mm
Number of minutes that the time zone differs from UTC.
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified month and year in the gYearMonth data type.

Examples
Simple

Invoking gYearMonth("2003-08") returns a gYearMonth value corresponding to August 2003, as shown in the following example query:

<result>{xs:gYearMonth("2003-08")}</result>

The preceding query, generates the following XML result:

<result>2003-08</result>

UTC Time Zone

Invoking gYearMonth("2003-08Z") returns a gYearMonth value corresponding to August 2003 in the UTC time zone, as shown in the following example query:

<result>{xs:gYearMonth("2003-08Z")}</result>

The preceding query, generates the following XML result:

<result>2003-08Z</result>

Error—Incorrect Format

Invoking gYearMonth("2003-8") outputs an error because the month is not specified using two digits.

For example, the following example query:

<result>{xs:gYearMonth("2003-8")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "2003-8" to type [gYearMonth@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C gYearMonth data type description

 


xs: gYear

Converts $string-var (a string in the gYear format) to the gYear data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the gYear format, the following error is reported:

Could not cast "invalid_gYear_string" to type [gYear@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_gYear_string is the string not valid to the time format, for example: "20-2003".

Signatures

xs:gYear(xs: string $string-var)—> xs: gYear

Table 4-17 Arguments
Data Type
Argument
Description
 
xs:string
$string-var
Represents a string with the year specified with one of the following formats
  • YYYY
  • YYYYZ
  • YYYY+hh:mm
  • YYYY-hh:mm
 
YYYY
Year.
+
Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC.
mm
Number of minutes that the time zone differs from UTC
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified year in the gYear data type.

Examples
Simple

Invoking gYear("2003") returns a gYearvalue corresponding to the year 2003, as shown in the following example query:

<result>{xs:gYear("2003")}</result>

The preceding query, generates the following XML result:

<result>2003</result>

UTC Time Zone

Invoking gYear("2003Z") returns a gYear value corresponding to the year 2003 in the UTC time zone, as shown in the following example query:

<result>{xs:gYear("2003Z")}</result>

The preceding query, generates the following XML result:

<result>2003Z</result>

Related Topics

W3C gYear data type description

 


xs: gMonthDay

Converts $string-var (a string in the gMonthDay format) to the gMonthDay data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the gMonthDay format, the following error is reported:

Could not cast "invalid_gMonthDay_string" to type [gMonthDay@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_gMonthDay_string is the string not valid to the time format, for example: "08-15".

Signatures

xs:gMonthDay(xs: string $string-var)—> xs:gMonthDay

Table 4-18 Arguments
Data Type
Argument
Description

xs:string

$string-var

Represents a string with the month and day specified with one of the following formats:

  • --MM-DD
  • --MM-DDZ
  • --MM-DD+hh:mm
  • --MM-DD-hh:mm
 
--
Beginning prefix.
MM
Month (as a number).
-
Separator between months and days.
DD
Day.
+
Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed.
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC.
mm
Number of minutes that the time zone differs from UTC.
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified month and day in the gMonthDay data type.

Examples
Simple

Invoking gMonthDay("--08-15") returns a gMonthDay value corresponding to August 15, as shown in the following example query:

<result>{xs:gMonthDay("--08-15")}</result>

The preceding query, generates the following XML result:

<result>--08-15</result>

UTC Time Zone

Invoking gMonthDay("--08-15Z") returns a gMonthDay value corresponding to August 15 in the UTC time zone, as shown in the following example query:

<result>{xs:gMonthDay("--08-15Z")}</result>

The preceding query, generates the following XML result:

<result>--08-15Z</result>

Error—Incorrect Format

Invoking gMonthDay("08-15") outputs an error because the -- prefix is missing.

For example, the following example query:

<result>{xs:gMonthDay("08-15")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "08-15" to type [gMonthDay@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C gMonthDay data type description

 


xs: gMonth

Converts $string-var (a string in the gMonth format) to the gMonth data type.

If the value of $string-var is the empty sequence, the empty sequence is returned.The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the gMonth format, the following error is reported:

Could not cast "invalid_gMonth_string" to type [gMonth@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_gMonth_string is the string not valid to the time format, for example: "08".

Signatures

xs:gMonth(xs: string $string-var)—> xs:gMonth

Table 4-19 Arguments 
Data Type
Argument
Description
xs:string
$string-var
Represents a string with the month and day specified with one of the following formats:
  • --MM--
  • --MM--Z
  • --MM--+hh:mm
  • --MM---hh:mm
 
--
Beginning prefix.
MM
Month (as a number).
--
Separator.
+
Positive time zone offset. (Optional) If a plus or minus is not specified, + is assumed.
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC.
mm
Number of minutes that the time zone differs from UTC.
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified month in the gMonth data type.

Examples
Simple

Invoking gMonth("--08--") returns a gMonth value corresponding to the month of August, as shown in the following example query:

<result>{xs:gMonth("--08--")}</result>

The preceding query, generates the following XML result:

<result>--08--</result>

UTC Time Zone

Invoking gMonth("--08--Z") returns a gMonth value corresponding to the month of August in the UTC time zone, as shown in the following example query:

<result>{xs:gMonth("--08--Z")}</result>

The preceding query, generates the following XML result:

<result>--08--Z</result>

Error—Incorrect Format

Invoking gMonth("08") outputs an error because the -- prefix is missing.

For example, the following example query:

<result>{xs:gMonth("08")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "08" to type [gMonth@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C gMonth data type description

 


xs: gDay

Converts $string-var (a string in the gDay format) to the gDay data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

If the value of $string-var is not valid to the gDay format, the following error is reported:

Could not cast "invalid_gDay_string" to type [gDay@http://www.w3.org/2001/XMLSchema] is displayed.

Where invalid_gDay_string is the string not valid to the time format, for example: "15".

Signatures

xs:gDay(xs: string $string-var)—>xs:gDay

Table 4-20 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents a string with the day specified with one of the following formats:
  • DD
  • DDZ
  • DD+hh:mm
  • DD-hh:mm
 
---
Beginning prefix.
DD
Day.
+
Positive time zone offset. This option is optional. If a plus or minus is not specified, + is assumed.
-
Negative time zone offset. (Optional)
hh
Number of hours that the time zone differs from UTC.
mm
Number of minutes that the time zone differs from UTC.
Z
Indicates that the time corresponds to the UTC time zone.

Returns

Returns the specified day in the gDay data type.

Examples
Simple

Invoking gDay("---15") returns a gDay value corresponding to the15th of the month, as shown in the following example query:

<result>{xs:gDay("---15")}</result>

The preceding query, generates the following XML result:

<result>---15</result>

UTC Time Zone

Invoking gDay("---15Z") returns a gDay value corresponding to the 15th of the month in the UTC time zone, as shown in the following example query:

<result>{xs:gDay("---15Z")}</result>

The preceding query, generates the following XML result:

<result>---15Z</result>

Error—Incorrect Format

Invoking gDay("15") outputs an error because the --- prefix is missing.

For example, the following example query:

<result>{xs:gDay("15")}</result>

Produces the following error:

Error occurred while executing XQuery: Could not cast "15" to type [gDay@http://www.w3.org/2001/XMLSchema]

Related Topics

W3C gDay data type description

 


xs: duration

Converts $string-var (a string in the duration format) to the duration data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:duration(xs: string $string-var)—> xs:duration

Table 4-21 Arguments 
Data Type
Argument
Description
xs:string
$string-var

Represents a string with the duration specified with one of the following formats:

  • PyYmMdDThHiMsS
  • -PyYmMdDThHiMsS
  • Note: Specifying the number of years, months, days, hours, minutes, or seconds is optional—any of the substrings: yY, mM, dD, hH, iM, or sS do not have to be specified. For example, the following are valid durations: P10Y, P1D, -P11M, -P10Y7D, P2YT5H, or P6YT5H10S.
 
-
Duration is a negative amount of time.
Note: If - is not specified, duration is a positive amount of time
P
The start of a duration string. The P must always be specified.
yY
y—number of years in the duration.
Y—years are specified in the duration.
mM
m—number of months in the duration.
M—months are specified in the duration.
dD
d—number of days in the duration.
D—days are specified in the duration.
T
The start of the time part of the duration string. The T must be specified if any minutes, hours, or seconds (hH, iM, or sS) are specified.
hH
h—number of hours in the duration.
H—years are specified in the duration.
iM
i—number of minutes in the duration.
M—minutes are specified in the duration.
sS
s—number of seconds in the duration.
Seconds can be specified up to 7 digits after the decimal place. (Format xx.xxxxxxx)
S—seconds are specified in the duration.

Returns

Returns a duration of time as a duration value.

Examples

duration with All Components

Invoking duration("P1Y2M4DT9H8M20S") returns a duration value corresponding to 1 year, 2 months, 4 days, 9 hours, 8 minutes, and 20 seconds, as shown in the following example query:

<result>{xs:duration("P1Y2M4DT9H8M20S")}</result>

The preceding query, generates the following XML result:

<result>P1Y2M4DT9H8M20S</result>

duration with Just Years

Invoking duration("P9Y") returns a duration value corresponding to 9 years, as shown in the following example query:

<result>{xs:duration("P9Y")}</result>

The preceding query, generates the following XML result:

<result>P9Y</result>

duration with Just Negative Months

Invoking duration("-P10M") returns a duration value corresponding to negative 10 months as shown in the following example query:

<result>{xs:duration("-P10M")}</result>

The preceding query, generates the following XML result:

<result>-P10M</result>

duration with Just Days and Seconds

Invoking duration("P4DT20S") returns a duration value corresponding to 4 days and 20 seconds, as shown in the following example query:

<result>{xs:duration("P4DT20S")}</result>

The preceding query, generates the following XML result:

<result>P4DT20S</result>

Related Topics

W3C duration data type description

 


xs: anyURI

Converts $string-var that contains a URI (Uniform Resource Identifier Reference) to the anyURI data type.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:anyURI(xs: string $string-var)—>xs: anyURI

Table 4-22 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents the conversion string that contains the URI (Uniform Resource Identifier Reference)

Returns

Returns the $string-var converted to anyURI data type.

Examples
Simple

When you invoke the following query:

<result>{xs:anyURI("http://www.acme.org/")}</result>

The preceding query generates the following result:

<result>http://www.acme.org/</result>

Related Topics

W3C anyURI data type description

 


xs: Name

Converts $string-var to the Name data type.

If the value of $string-var is the empty sequence the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:Name(xs: string $string-var)—> xs: Name

Table 4-23 Arguments
Data Type
Argument
Description
xs:string
$string-var
Represents the string to convert

Returns

Returns the $string-var converted to the Name data type.

Related Topics

W3C Name data type description

 


xs: QName

Creates a new QName with a local name specified $string-var and no namespace.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

Signatures

xs:QName(xs: string $string-var)—> xs: QName

Table 4-24 Arguments
Data Type
Argument
Description
xs:String
$string-var
Represents the string to convert.

Returns

Returns the $string-var converted to the QName data type.

Related Topics

W3C QName data type description


  Back to Top       Previous  Next