[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: method to parse date time stamp
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|