Subject: Re: [xsl] method to parse date time stamp From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Wed, 31 Jan 2001 20:16:38 +0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] method to parse date time sta, Walter Torres | Thread | [xsl] generating ampersand for html, Robert Gretta |
RE: [xsl] Paradigm clash between XM, Christopher P. Wang | Date | [xsl] matching <br/> v. <br></br>, Robert Koberg |
Month |