Name

[2.0] hours-from-duration()

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

Syntax

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

Inputs

An xs:duration.

Output

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

<?xml version="1.0"?>
<!-- hours-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 hours 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 hours component of this duration ...

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.