XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (523 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
2.63Mb size Format: txt, pdf, ePub
ads

Signature

Argument
Type
Meaning
input
Numeric?
The supplied number.
Result
Numeric?
The absolute value of the supplied number. The result has the same type as the input
.

Effect

If the supplied number is positive, then it is returned unchanged. If it is negative, then the result is
-$input
.

Negative zero and negative infinity become positive zero and positive infinity. Positive zero, positive infinity, and NaN are returned unchanged. If the argument is an empty sequence, the result is an empty sequence.

The result has the same primitive numeric type as the input. For example, if the input value is an
xs:integer
, the result will be an
xs:integer
, and if the input is an
xs:double
, the result will be an
xs:double
.

Primitive here means one of the four types
xs:double
,
xs:float
,
xs:decimal
, and
xs:integer
. Clearly, if the input is an
xs:negativeInteger
, the result cannot also be an
xs:negativeInteger
—it will actually be an
xs:integer
. If the input is an
xs:positiveInteger
, you have a guarantee that the result will be an
xs:integer
, but this doesn't prevent the system returning something that is actually a subtype of
xs:integer
—for example, it would be legitimate to return the original
xs:positiveInteger
unchanged.

Examples

Expression
Result
abs(2)
2
abs(-2)
2
abs(-3.7)
3.7
abs(-1.0e-7)
1.0e-7
abs(number(‘NaN’))
NaN

adjust-date-to-timezone, adjust-dateTime-to-timezone, adjust-time-to-timezone

This entry describes a collection of three closely related functions. These functions have the effect of returning a date, time, or dateTime based on a supplied date, time, or dateTime, modified by adding, removing, or altering the timezone component of the value.

Signature

Argument
Type
Meaning
input
xs:date?, xs:dateTime?
, or
xs:time?
The date, time, or dateTime value whose timezone is to be adjusted. The type of this value must correspond to the name of the function invoked. For example, in the case of
adjust-time-to-timezone()
it must be an
xs:time
value.
timezone
(optional)
xs:dayTimeDuration?
Specifies the new timezone value. If this argument is omitted, the effect is the same as setting it to the result of the function
implicit-timezone()
.
Result
xs:date?, xs:dateTime?
, or
xs:time?
The adjusted date, dateTime, or time value
.

Effect

If the
input
is an empty sequence, the result is an empty sequence.

If there is no
timezone
argument (that is, if the function is called with a single argument), the effect is the same as calling the function with a second argument of
implicit-timezone()
. This adjusts the value to the timezone supplied in the dynamic context, which ideally will be the timezone where the user is located.

If the
timezone
argument is supplied, and is not an empty sequence, then it must be a duration between −50400 seconds and +50400 seconds, that is ±14 hours. To specify a timezone one hour ahead of UTC, write
xs:dayTimeDuration(“PT1H”)
.

These functions can be used to remove a timezone from a value that has a timezone, to add a timezone to a value that lacks a timezone, or to return the value that is equivalent to the supplied value, but in a different timezone. These effects are summarized in the table below.

Existing timezone
timezone argument is ()
timezone argument is not ()
Absent
returns the input value unchanged
result has the same components as input, with the addition of the specified timezone
Present
result is the localized value of the input, with the timezone removed
result represents the same instant as the input value, but in a different timezone

The only complex case here is the one in the bottom-right cell of the table, where the supplied value already has a timezone and this is to be replaced with a new timezone. The effect varies slightly depending on which if the three functions is used:

  • For an
    xs:dateTime
    , the result is an
    xs:dateTime
    that represents the same instant in time as the input value, but in the new timezone.
  • For an
    xs:time
    , the result is an
    xs:time
    that represents the time in the new timezone that is simultaneous with the time provided as the input value.
  • For an
    xs:date
    , the date is converted to an
    xs:dateTime
    representing 00:00:00 on the specified date; the requested adjustment is applied to this
    xs:dateTime
    value, and the result is the date part of the adjusted
    xs:dateTime
    .

Examples

Assume that
$CET
is set to the timezone value
+01:00
, represented by the
xs:dayTimeDuration
PT1H
. Assume that
$EST
is set to the timezone value
-05:00
, represented by the
xs:dayTimeDuration
-PT5H
. Assume also that the implicit timezone is the timezone value
-08:00
, represented by the
xs:dayTimeDuration
-PT8H
.

Here are some examples using
xs:time
values:

Expression
Result
adjust-time-to-timezone( xs:time(“15:00:00+01:00”), $EST)
09:00:00-05:00
adjust-time-to-timezone( xs:time(“15:00:00”), $EST)
15:00:00-05:00
adjust-time-to-timezone( xs:time(“15:00:00+01:00”))
06:00:00-08:00
adjust-time-to-timezone( xs:time(“15:00:00+01:00”), ())
15:00:00
adjust-time-to-timezone( xs:time(“15:00:00”), ())
15:00:00

The corresponding examples using
xs:dateTime
values are:

Expression
Result
adjust-dateTime-to-timezone
(
xs:dateTime(“2008-03-01T15:00:00+01:00”), $EST)
2008-03-01T09:00:00-05:00
adjust-dateTime-to-timezone
(
xs: dateTime(“2008-03-01T15:00:00”),
$EST)
2008-03-01T15:00:00-05:00
adjust-dateTime-to-timezone
(
xs: dateTime(“2008-03-01T15:00:00+01:00”))
2008-03-01T06:00:00-08:00
adjust-dateTime-to-timezone
(
xs:dateTime(“2008-03-01T15:00:00+01:00”), ())
2008-03-01T15:00:00
adjust-dateTime-to-timezone
(
xs: dateTime(“2008-03-01T15:00:00”), ())
2008-03-01T15:00:00

Adjusting the timezone component of a date is a less intuitive operation, but is still well defined:

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
2.63Mb size Format: txt, pdf, ePub
ads

Other books

Unexpected by Lietha Wards
The Gift-Giver by Joyce Hansen
The Summons by John Grisham
All the King's Horses by Laura C Stevenson
In The Royal Manner by Paul Burrell
Battle Dress by Amy Efaw
Tackling Her Heart by Alexandra O'Hurley
Sleight of Hand by Robin Hathaway