XSLT and XPath function reference in alphabetical order
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)
Value extraction from time values, date values and duration
An integer of xs:integer type which corresponds to the value of the hours component of the duration value put into canonical form and passed on.
Optional. A duration indication of xs:dayTimeDuration type of the PnDTnHnMnS form from which – after conversion into its canonical form – the so resulting value of the hours component is extracted. If the empty sequence is passed on, the function returns the empty sequence.
Purpose of use:
The function returns an integer which results from the hours component of the duration value provided that the value is in canonical form. All other components (days, minutes, seconds) are rejected.
If the value is not in canonical form PnDThHmMsS (with n optional, h, m, s < 60), all components are first put into canonical form. This is done, if possible, by converting each individual component into integer values of the next higher component while retaining the residual value (example: PT26H becomes P1DT2H). For negative duration values the returned value is accordingly negative.
Example 1 - hours component from duration value:
Results in: 10.
The duration indication is in canonical form. In this simplest case, the hours component can be gained directly by rejecting all other components.
Example 2 - value with minutes and hours component:
Results in: 12.
Analogous to example 1 – here, however, besides the day component, also the components for minutes and seconds are rejected.
Example 3 - duration value in non-canonical form:
Results in: 3.
The duration indication is not in canonical form. The hours component is firstly converted to whole days and remaining hours (P5DT3H; 5 days and 3 hours), the rest of the hours component is returned.
Example 4 - hours from negative duration value:
Results in: -10.
The duration indication is in canonical form, but negative. Therefore, the value of the hours component (10H) is returned with a minus sign.
The function is not available.
fn:hours-from-duration($arg as xs:duration?) as xs:integer?
|<< back||next >>|
Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany