XSLT and XPath function reference in alphabetical order

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

fn:seconds-from-duration

Category:

Value extraction from time values, date values and duration

Origin:

XPath 2.0

Return value:

A xs:decimal decimal number which corresponds to the value of the seconds and split seconds of the duration value passed on and converted to canonical form.

Call/Arguments:

fn:seconds-from-duration($durationValue)

$durationValue:

Optional. A duration indication of xs:duration type from which the value of the seconds component is extracted. If the argument is the empty sequence, the function returns an empty result sequence.

Purpose of use:

The function accepts a xs:duration duration value from which a xs:dayTimeDuration value is determined by removing possible year and month components. This value, where appropriate, is put into canonical form PnDTnHnMnS.

fn:seconds-from-duration() returns a decimal number which corresponds to the seconds component (entire seconds and split seconds) of a xs:dayTimeDuration duration value, provided that the value is in canonical form. All the other components (days, hours, minutes) are rejected.

If the input value has the xs:yearMonthDuration type, so, after conversion into the xs:dayTimeDuration type, the return value is 0, since in this case, no seconds component is contained.

If the xs:dayTimeDuration value is not in canonical form PnDThHmMsS (with n optional; h, m, s < 60), its components are initially put into canonical form. This happens, if possible, by conversion of each single component into integer values of the next higher component while retaining the residual value (example: PT130S becomes PT2M10S). For negative duration values, the returned value is accordingly negative.

Example 1 – seconds from canonical duration value:

fn:seconds-from-duration(

xs:dayTimeDuration("P5DT12H30M25.8S")

)

results in: 25.8.

The duration value is already in canonical form, therefore the value of the seconds component can be directly outputted as xs:decimal.

Example 2 – seconds from non-canonical duration value:

fn:seconds-from-duration(

xs:dayTimeDuration("-PT130S")

)

results in: -10.0.

The canonisation of the value is achieved by the conversion of the present seconds value into minutes and seconds (-P2M10S). The outputted value is negative because the input value is negative. A decimal place is attached to the integer result in order to cope with the xs:decimal output type.

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:seconds-from-duration($arg as xs:duration?) as xs:decimal?

   

<< 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