0

Having seen Date operations on xsl 1.0

<xsl:template name="JDN">
<xsl:param name="date"/>
<xsl:param name="year" select="substring($date, 1, 4)"/>
<xsl:param name="month" select="substring($date, 6, 2)"/>
<xsl:param name="day" select="substring($date, 9, 2)"/>
<xsl:param name="a" select="floor((14 - $month) div 12)"/>
<xsl:param name="y" select="$year + 4800 - $a"/>
<xsl:param name="m" select="$month + 12*$a - 3"/>
<xsl:value-of select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />

I'd like to have a reference back to something a bit more concrete, rather than a stack overflow answer...it seems to work!....and I believe its based on some standard mathematical model for datetimes...is there some sort of canonical XSLT 1.0 implementation? published in a book or a library? i.e. how do I know there isn't a typo? I think implementing the model in XSLT is non trivial, I don't want to have to reinvent the wheel.

MrD at KookerellaLtd
  • 2,412
  • 1
  • 15
  • 17

2 Answers2

2

I wrote the above template based on the algorithm published in the Wikipedia's entry on Julian Day. They have since changed to another algorithm. If you want the source of the original algorithm, you will need to browse the article's revision history.

There are no "canonical" or "authoritative" sources for XSLT, other than the XSLT specifications published by the World Wide Web Consortium (W3C). Anyone with access to the algorithm can check the correctness of the implementation for themselves (and are strongly encouraged to do so, for anything they find on the Internet).

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
0

I have seen this template in an O'Reilly's book: https://www.oreilly.com/library/view/xslt-cookbook-2nd/0596009747/ch04.html (this of course doesn't guarantee that it's correct, but there can also be bugs in more formal datetime libraries.)

If you are stuck with XSLT 1.0, you can also defer to the EXSLT date module if your processor supports it (http://exslt.org/date/). MSXML allows you to insert Javascript or C# code depending on the version.

wasmachien
  • 969
  • 1
  • 11
  • 28