18 June 2003
I’ve spent the last couple of hours implementing ESF .
‘Hours?’ you say, ‘how can you take hours over implementing something so simple?’ Well, there are three reasons:
So now I have an
XSL stylesheet that converts an
RDF/RSS
file to painlessly. I’m running it server-side, in fact: choose a feed and append ?alternate=esf to the URL. You’ll be presented with ESF, sent as text/plain. (I think that’s right, but the spec doesn’t say.)
Most of this was easy. Thanks to Chriztian Steinmeier and Eric Meyer I found out about the xsl:space attribute. That didn’t make things easier, as such, just less ugly.
The real head-scratcher was generating Epoch time from the
W3C
DTF
. It’s not as distastrous as I first thought it was going to be, actually. I made a template called epoch_time that you call with params of year (note: subtract 1970 from it before you call the template; it’s easier that way), month, day, hours, minutes, and seconds. Parsing these out using the substring functions in XPath was easy enough, so all that remained was to convert them.
I don’t know of a simple formula for calculating this sort of thing, and if I’ve done it in maths lessons then I’ve forgotten it. What this template does is:
floor($years * 0.25). We know that 1970 wasn’t a leap year, so all OK there.I could have shoehorned the last two into the same expression but it would have been even less easy to read than it is now. No, it doesn’t do timezones — does it have to?
Improvements, comments, etc. welcome.