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



Value extraction from time values, date values and duration


XPath 2.0

Return value:

An integer of xs:integer type which represents the year of the normalised date value passed on.




A date value of xs:date type from whose normalised form the year shall be extracted.

Purpose of use:

The function returns an integer of xs:integer type which corresponds to the year component of the normalised date value passed on. An implicit timezone factor, if available, is included. If the input value is the empty sequence, the function returns an empty result sequence.

Example 1 - extraction of the year from a date value:

fn:year-from-date( xs:date("2007-05-31")


results in the value: 2007.

In this example, an implicit timezone indication of -5:00 was assumed, accordingly -PT5H0M. Because of the normalisation, there is no difference for the year outputted. However, this may be different in borderline cases – see the following example.

Example 2 - date change by normalisation:

fn:year-from-date( xs:date("2008-01-01+05:00")


results in the value: 2007.

In this example, an implicit timezone indication of -5:00 was assumed, accordingly -PT5H0M. During the normalisation of the date value, the original timezone factor is subtracted and the new one is added. Here, the implicit time indication T00:00:00 – (+05:00) + (-05:00) results in a jump to T14:00:00 of the previous day which causes a date change and as a consequence, the output of the year 2007.

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:year-from-date($arg as xs:date?) 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