fyi... little snippets of useful code :)
--e
-----Original Message-----
From: [log in to unmask] [mailto:[log in to unmask]]
Sent: Wednesday, October 25, 2000 6:48 PM
To: [log in to unmask]
Subject: [RSS-DEV] Submission - time/Date stylesheet
Hello all:
Attached is an XSLT Stylesheet and source code for a Java helper class
which deals with dates in ISO 8601 format, which is the timestamp
format
used by Dublin Core, XML Schemas, etc.
See http://www.w3.org/TR/NOTE-datetime for more on this format.
I've used this stylesheet/Java class combo with Apache's Xalan
(xalan_1_2_D02.jar) but have not tested it with XT.
Thanks much to [log in to unmask] for the RSS 1.0 stylesheets!
Hope this helps!
-- boyd
---------
Boyd Waters [log in to unmask]
National Radio Astronomy Observatory http://www.nrao.edu
PO Box 0 Socorro, NM 87801 505.835.7346
http://www.zocalo.net/~waters
[log in to unmask]
---------
// ISODateTest.java
import java.text.*;
import java.util.*;
import boyd.util.ISODateFormat;
public class IOSDateTest {
public static void main(String[] args) {
ISODateFormat formatter = new ISODateFormat(
ISODateFormat.DATE_TIME_FRAC );
System.out.println(formatter.format( new Date(36000000) ));
System.out.println( formatter.format( new Date() ) );
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- timestamp.xsl -- deal with web-formatted dates
This stylesheet uses a Java helper class boyd.util.ISODateFormat to
transform
dates that conform to the ISO 8601 / W3C timestamp formatting.
see http://www.w3.org/TR/NOTE-datetime
I've got this stylesheet and Java class working with
Apache Xalan (xalan_1_2_D02.jar) but have not tested it with XT.
//#####################################################################
//# Copyright (C) 2000 Associated Universities, Inc. Washington DC,
USA.
//#
//# This program is free software; you can redistribute it and/or
modify
//# it under the terms of the GNU General Public License as published
by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
but
//# WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//# General Public License for more details.
//#
//# You should have received a copy of the GNU General Public License
//# along with this program; if not, write to the Free Software
//# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//#
//# AUTHOR:
//# Boyd Waters <[log in to unmask]>
//# http://www.aoc.nrao.edu/~bwaters
//#
//# REVISION-HISTORY:
//# Wed Oct 25 15:50:49 2000
-->
<xsl:stylesheet version="1.0"
xmlns:xsl ="http://www.w3.org/1999/XSL/Transform"
xmlns:java ="http://xml.apache.org/xslt/java"
xmlns:dc ="http://purl.org/dc/elements/1.1/"
>
<!-- Global Vars -->
<xsl:variable name="parser"
select="java:boyd.util.ISODateFormat.new()"/>
<xsl:variable name="formatter"
select="java:boyd.util.ISODateFormat.new()"/>
<!-- main helper function -->
<xsl:template name="format-date-number">
<xsl:param name="date"
select="java:getTime(java:java.util.Date.new())"/>
<xsl:param name="format" />
<xsl:value-of select="java:applyPattern($formatter,
string($format))"/>
<xsl:value-of select="java:format($formatter, $date)"/>
</xsl:template>
<!-- templates which match and then apply the main function -->
<!-- Dublin Core dates are ISO-formatted timestamps -->
<xsl:template match="timestamp[@type='iso'] | dc:date">
<xsl:call-template name="format-date-number">
<xsl:with-param name="format" select="string(./@format)"/>
<xsl:with-param name="date"
select="java:getTime( java:parseISO( $parser,
normalize-space(string(.))))"/>
</xsl:call-template>
</xsl:template>
<!-- a timestamp can also be represented as the number of milliseconds
since the epoch (midnight 01 Jan 1970) -->
<xsl:template match="timestamp[@type='ms']">
<xsl:call-template name="format-date-number">
<xsl:with-param name="date" select="number(.)"/>
</xsl:call-template>
</xsl:template>
<!-- If no type attribute is given, then we assume you want the
current time, which is the time that this stylesheet is
applied. Any content of the tag is IGNORED -->
<xsl:template match="timestamp">
<xsl:call-template name="format-date-number">
<xsl:with-param name="format" select="string(./@format)"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
To unsubscribe from this group, send an email to:
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|