Name

[2.0] days-from-duration()

Given an xs:duration value, returns the number of days in that duration.

Syntax

xs:integer? days-from-duration(xs:duration?)

Inputs

A xs:duration.

Output

An xs:integer representing the days component of the given xs:duration. Be aware that for an xs:yearMonthDuration, this function always returns 0 because there is no days component of an xs:yearMonthDuration. Also, if the input 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 days-from-duration() function with all three types of durations:

<?xml version="1.0"?>
<!-- days-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>&#xA;Extracting the days 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>&#xA;&#xA; A sample xs:duration: </xsl:text> <xsl:value-of select="$sampleDuration"/> <xsl:text>&#xA; The days component of this duration is </xsl:text> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.