Get the next day of a date
This is an open discussion with 4 replies, filed under XSLT.
Search
Wouldn't this the be much simpler using EXSLT's date functions? (And leap years would also work!)
This stylesheet can give you a start:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date"> <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <xsl:param name="date" select="'2012-02-28'"/> <data> <date> <xsl:value-of select="$date"/> </date> <one-day-after-date> <xsl:value-of select="date:add($date, 'P1D')"/> </one-day-after-date> <two-days-after-date> <xsl:value-of select="date:add($date, 'P2D')"/> </two-days-after-date> </data> </xsl:template> </xsl:stylesheet>
The output will be:
<data> <date>2012-02-28</date> <one-day-after-date>2012-02-29</one-day-after-date> <two-days-after-date>2012-03-01</two-days-after-date> </data>
[EDIT]: Simplified stylesheet.
I see it as a challenge. Here is the latest version with leap year.
:-)
I was wondereing why it didn’t work in my case just now. I borked up the namespace … thanks to this page I found the error :)
thanks Michael!
Create an account or sign in to comment.
A new XSLT utility, "Get the next day of a date" is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.