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 month component of the input value put into canonical form.
A xs:duration duration indication from which, after conversion into the xs:yearMonthDuration type in its canonical form PnYmM, the value of the month component resulting from this is extracted. If the empty sequence is passed on, the funtion returns the empty result sequence.
Purpose of use:
The function returns an integer between 0 and 11 which results from the month 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 day, hours, minutes and seconds components from the duration value with subsequent canonisation.
If a xs:dayTimeDuration type was 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 month component into integer values of the year component.
The residual value corresponding to the canonical month value is outputted (example: P130M becomes P5Y10M). For negative duration values, the returned value is also negative (see example 2).
Example 1 - months from duration value:
Results in the value: 2.
The value is not in canonical form. The current month value of 14 is firstly converted to 1 year, 2 months (canonised). The residual value of 2 is outputted as result of the function.
Example 2 - months from duration value:
Results in the value: -6.
The value is not in canonical form. The current month value of 18 is firstly converted to 1 year, 6 months (canonised) – the residual value of 6 is outputted with negative leading sign as the result of the function because the duration value is negative.
The function is not available.
fn:months-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