Reputation: 15
I am trying to format a date using an xslt style sheet in order to return the first day of the current year. I am also trying to do this for an to return the last day of the current year. Here is the current version of XML and schema I am using :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
The code I am currently using to retrieve the dates:
<StartDate>
<xsl:value-of select="../Start_Date"/>
</StartDate>
<EndDate>
<xsl:value-of select="../End_Date"/>
</EndDate>
Upvotes: 1
Views: 1179
Reputation: 117073
In XSLT 2.0 or higher, you can output the date of the first day of the current year using:
<xsl:value-of select="format-date(current-date(), '[Y]-01-01')" />
or, if you prefer:
<xsl:value-of select="year-from-date(current-date())"/>
<xsl:text/>-01-01<xsl:text/>
Similarly, the date of the last day of the current year can be produced using:
<xsl:value-of select="format-date(current-date(), '[Y]-12-31')" />
or:
<xsl:value-of select="year-from-date(current-date())"/>
<xsl:text/>-12-31<xsl:text/>
Upvotes: 1