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 years component of the input value.
A xs:duration duration indication from which, after conversion into the xs:yearMonthDuration type in its canonical form PnYmM, the value of the years component resulting from this is extracted. If the empty sequence is passed on, the funtion returns an empty result sequence.
Purpose of use:
The function returns an integer which results in the value of the years component of a duration value after transferring the input value which may be of any xs:duration type into the canonical form of xs:yearMonthDuration. This is done by removing the days, hours, minutes and seconds components from the duration value with subsequent canonisation.
If a xs:dayTimeDuration type has been passed on, it can be converted to the required xs:yearMonthDuration type – however, all of its components have the value 0, which is why the function consequentially returns the value 0 for the month component.
If a xs:yearMonthDuration value passed on is not in the canonical form PnYmM (with n optional, m < 12), the components are firstly put into canonical form. This is done by converting the months component into integer values of the years component.
The extracted value results from the sum of all components whose values aggregate to at least one year, which means the Y component as well as the M component for values greater than or equal to 12. Residual values of the M component are rejected. The result value for negative duration values is accordingly negative.
Example 1 - years from a positive duration value:
results in the value: 23, accordingly 22 years + 12 months + 6 months. The rest of the duration value is rejected.
Example 2 - years from a negative duration value:
results in the value: -1, accordingly -(12 months + 6 months). Here, the rest of the duration value is also rejected.
The function is not available.
fn:years-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