This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: method to parse date time stamp
- To: "Walter Torres" <walter at torres dot ws>
- Subject: Re: [xsl] method to parse date time stamp
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Wed, 31 Jan 2001 20:16:38 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <00be01c08bbb$50dbef30$9654b23f@ELOY1499>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Walter,
> Is there a "better" way to do this?
Well, there aren't any XPath functions that deal with dates, if that's
what you're asking, so you are stuck with lumbering string
manipulation. One slightly weird thing about your solution is:
<xsl:variable name='year' select='substring( $datetime, 0 , 5 )' />
Indexes in XSLT start at 1 rather than 0, so the above is the same as:
<xsl:variable name='year' select='substring( $datetime, 1 , 4 )' />
which probably makes a bit more sense because you're getting 4
characters, not 5.
You could do the same thing as above with substring-before($datetime,
'-') but that's probably (?) less efficient given that you know the
precise indexes and lengths of the strings you're after.
You *probably* want to put the '-' separating the date and the time
within an xsl:text element to stop it having lots of whitespace in it:
<xsl:text> - </xsl:text>
Oh, and of course there's no need to use all those variables: you
could just do:
<!-- timestamp NODE Template -->
<xsl:template match='pubdate'>
<td>
<xsl:value-of select="concat(
substring(., 6, 2), '/', substring(., 9, 2), '/',
substring(., 1, 4), ' - ', substring(., 12, 8))" />
</td>
</xsl:template>
if you were *really* after brevity.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list