15 Context functions

The following functions are defined to obtain information from the static or dynamic context.

Function Meaning
fn:position Returns the context position from the dynamic context.
fn:last Returns the context size from the dynamic context.
fn:current-dateTime Returns the current date and time (with timezone).
fn:current-date Returns the current date.
fn:current-time Returns the current time.
fn:implicit-timezone Returns the value of the implicit timezone property from the dynamic context.
fn:default-collation Returns the value of the default collation property from the static context.
fn:default-language Returns the value of the default language property from the dynamic context.
fn:static-base-uri This function returns the value of the static base URI property from the static context.

15.1 fn:position

Summary

Returns the context position from the dynamic context.

Signature
fn:position() as xs:integer
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-dependent·.

Rules

Returns the context position from the dynamic context. (See Section C.2 Dynamic Context Components XP31.)

Error Conditions

A dynamic error is raised [err:XPDY0002]XP if the context item is absentDM40.

15.2 fn:last

Summary

Returns the context size from the dynamic context.

Signature
fn:last() as xs:integer
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-dependent·.

Rules

Returns the context size from the dynamic context. (See Section C.2 Dynamic Context Components XP31.)

Error Conditions

A dynamic error is raised [err:XPDY0002]XP if the context size is absentDM40.

Notes

Under most circumstances, the context size is absent only if the context item is absent. However, XSLT 3.0 with streaming defines situations in which the context item and context position are known, but the context size is unknown.

Examples

The expression (1 to 20)[fn:last() - 1] returns 19.

15.3 fn:current-dateTime

Summary

Returns the current date and time (with timezone).

Signature
fn:current-dateTime() as xs:dateTimeStamp
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on implicit timezone.

Rules

Returns the current dateTime (with timezone) from the dynamic context. (See Section C.2 Dynamic Context Components XP31.) This is an xs:dateTime that is current at some time during the evaluation of a query or transformation in which fn:current-dateTime is executed.

This function is ·deterministic·. The precise instant during the query or transformation represented by the value of fn:current-dateTime() is ·implementation-dependent·.

If the implementation supports data types from XSD 1.1 then the returned value will be an instance of xs:dateTimeStamp. Otherwise, the only guarantees are that it will be an instance of xs:dateTime and will have a timezone component.

Notes

The returned xs:dateTime will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context

Examples

fn:current-dateTime() returns an xs:dateTimeStamp corresponding to the current date and time. For example, a call of fn:current-dateTime() might return 2004-05-12T18:17:15.125Z corresponding to the current time on May 12, 2004 in timezone Z.

15.4 fn:current-date

Summary

Returns the current date.

Signature
fn:current-date() as xs:date
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on implicit timezone.

Rules

Returns xs:date(fn:current-dateTime()). This is an xs:date (with timezone) that is current at some time during the evaluation of a query or transformation in which fn:current-date is executed.

This function is ·deterministic·. The precise instant during the query or transformation represented by the value of fn:current-date is ·implementation-dependent·.

Notes

The returned date will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context

Examples

fn:current-date() returns an xs:date corresponding to the current date. For example, a call of fn:current-date() might return 2004-05-12+01:00.

15.5 fn:current-time

Summary

Returns the current time.

Signature
fn:current-time() as xs:time
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on implicit timezone.

Rules

Returns xs:time(fn:current-dateTime()). This is an xs:time (with timezone) that is current at some time during the evaluation of a query or transformation in which fn:current-time is executed.

This function is ·deterministic·. The precise instant during the query or transformation represented by the value of fn:current-time() is ·implementation-dependent·.

Notes

The returned time will always have an associated timezone, which will always be the same as the implicit timezone in the dynamic context

Examples

fn:current-time() returns an xs:time corresponding to the current time. For example, a call of fn:current-time() might return 23:17:00.000-05:00.

15.6 fn:implicit-timezone

Summary

Returns the value of the implicit timezone property from the dynamic context.

Signature
fn:implicit-timezone() as xs:dayTimeDuration
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on implicit timezone.

Rules

Returns the value of the implicit timezone property from the dynamic context. Components of the dynamic context are described in Section C.2 Dynamic Context Components XP31.

15.7 fn:default-collation

Summary

Returns the value of the default collation property from the static context.

Signature
fn:default-collation() as xs:string
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on collations.

Rules

Returns the value of the default collation property from the static context. Components of the static context are described in Section C.1 Static Context Components XP31.

Notes

The default collation property can never be absent. If it is not explicitly defined, a system defined default can be invoked. If this is not provided, the Unicode codepoint collation (http://www.w3.org/2005/xpath-functions/collation/codepoint) is used.

15.8 fn:default-language

Summary

Returns the value of the default language property from the dynamic context.

Signature
fn:default-language() as xs:language
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on default language.

Rules

Returns the value of the default language property from the dynamic context. Components of the dynamic context are described in Section 2.1.2 Dynamic Context XP31.

Notes

The default language property can never be absent. The functions fn:format-integer, fn:format-date, fn:format-time, and fn:format-dateTime are defined to use the default language if no explicit language is supplied. The default language may play a role in selection of a default collation, but this is not a requirement.

15.9 fn:static-base-uri

Summary

This function returns the value of the static base URI property from the static context.

Signature
fn:static-base-uri() as xs:anyURI?
Properties

This function is ·deterministic·, ·context-dependent·, and ·focus-independent·. It depends on static base URI.

Rules

The function returns the value of the static base URI property from the static context. If the property is absent, the empty sequence is returned.

Components of the static context are described in Section 2.1.1 Static Context XP31 .

Notes

XQuery 3.0 and XSLT 3.0 give an implementation freedom to use different base URIs during the static analysis phase and the dynamic evaluation phase, that is, for compile-time and run-time resources respectively. This is appropriate when the implementation allows the output of static analysis (a "compiled" query or stylesheet) to be deployed for execution to a different location from the one where static analysis took place. In this situation, the fn:static-base-uri function should return a URI suitable for locating resources needed during dynamic evaluation.