I don't think date() should be a function, you need the xs:date() data type.
Add the xs namespace and then the xs:date() prefix.
In the following stylesheet, 2012 will be created using any valid XML input:
<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:variable name="dateValue" select="'2012-03-19'"/> <xsl:variable name="year" select="year-from-date(xs:date($dateValue))"/> <xsl:value-of select="$year"/> </xsl:template> </xsl:stylesheet>
Note that you must also quote your select in your "dateValue" xsl:variable .
Daniel Haley
source share