Archive for March, 2005

XSLT Cookbook: Generating an RFC 822 Date

Problem
You want to generate an RFC 822-formatted date in XSLT. This is needed, for example, in RSS feeds.

Solution
Use this code:


<xsl:value-of select="concat(date:day-abbreviation(), ', ', 
  format-number(date:day-in-month(), '00'), ' ', 
  date:month-abbreviation(), ' ', date:year(), ' ', 
  format-number(date:hour-in-day(), '00'), ':', 
  format-number(date:minute-in-hour(), '00'), ':', 
  format-number(date:second-in-minute(), '00'), ' GMT')"/>

This assumes your server is in GMT.

Discussion
XSL uses a different default date format style than RSS, so it’s a bit of a pain to generate the current date in the RFC 822 format.

This code requires the use of the EXSLT date functions. Add them to your stylesheet by modifying the top to look like this:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:date="http://exslt.org/dates-and-times"
                extension-element-prefixes=date"
                version="1.0">

I use the format-number() function to make sure all numbers have leading 0s. The date functions return 3 instead of 03, for example.

Yahoo! Search Web Services

Yahoo! Search has just launched a Web service:

http://developer.yahoo.net/

You can search five databases: web, local, news, image, and video.

It’s completely free to use for all personal and non-commercial projects and it’s totally REST-based. No SOAP.

There’s an SDK. It’s released as open source under the BSD license.

http://developer.yahoo.net/download/

There are examples in all the major languages: Java, JavaScript, Perl, PHP, and Python.

They’re hosting applications on a Wiki:

http://developer.yahoo.net/wiki/index.cgi?ApplicationList

So far, there’s a Firefox Sidebar and an Image search application.

More links and information: