last-modified() extension function?
Added by Anonymous almost 18 years ago
Legacy ID: #4102143 Legacy Poster: Brian Lalonde (brianiac)
I'm writing an RSS transform, and I'd like to include the lastmod dateTime of each separate source document. Is there an extension function that will return the modification dateTime, given a URI?
Replies (2)
RE: last-modified() extension function? - Added by Anonymous almost 18 years ago
Legacy ID: #4102172 Legacy Poster: Michael Kay (mhkay)
It's easy enough to do this kind of thing by making calls on the standard Java class library. Something like: <xsl:function name="f:last-modified" as="xs:dateTime" xmlns:File="java:java.io.File"> <xsl:param name="uri" as="xs:string"/> <xsl:if test="starts-with($uri, 'file:/')"> <xsl:variable name="file" select="File:new(substring-after($uri, 'file:/'))"/> <xsl:variable name="last-mod" as="xs:integer" select="File:lastModified($file)"/> <xsl:sequence select="f:javaDateTime($last-mod)"/> </ </ (plus some error handling, plus support for file:/// as well as file:/) <xsl:function name="f:javaDateTime" as="xs:dateTime"> <xsl:param name="in" as="xs:integer"/> <xsl:sequence select="xs:dateTime('1970-01-01T00:00:00Z') + $in * xs:dayTimeDuration('PT0.001S')"/> </xsl:function> Michael Kay
Thanks again - Added by Anonymous almost 18 years ago
Legacy ID: #4102260 Legacy Poster: Brian Lalonde (brianiac)
That should work for this situation just fine. (Even in .NET.) Thanks! It could be helpful in the future if there were something generic that would also be able to handle http:, https:, and ftp: schemes (maybe nntp:, rtsp:, dav:, imap:, etc.).
Please register to reply