Name
[2.0]
seconds-from-duration()
Given an xs:duration value,
returns the number of seconds in that duration.
Syntax
xs:decimal?seconds-from-duration(xs:duration?)
Inputs
An xs:duration
value.
Output
An xs:decimal
representing the seconds component of the given xs:duration. Be aware that for an
xs:yearMonthDuration, this
function always returns 0
because there is no seconds component of an xs:yearMonthDuration. Also, if the
argument is the empty sequence, this function returns the empty
sequence.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 10.5, “Component Extraction Functions on Durations, Dates and Times.”
Example
This stylesheet demonstrates the seconds-from-duration() function
with all three types of durations:
<?xml version="1.0"?>
<!-- seconds-from-duration.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:text>
Extracting the seconds component from durations:</xsl:text> <xsl:variable name="sampleDuration" as="xs:duration" select="xs:duration('P3Y8M2DT4H23M12.2S')"/> <xsl:variable name="sampleYearMonthDuration" as="xs:yearMonthDuration" select="xs:yearMonthDuration('P3Y8M')"/> <xsl:variable name="sampleDayTimeDuration" as="xs:dayTimeDuration" select="xs:dayTimeDuration('P2DT4H23M12.2S')"/> <xsl:text>

 A sample xs:duration: </xsl:text> <xsl:value-of select="$sampleDuration"/> <xsl:text>
 The seconds component ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access