[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: method to parse date time stamp

Subject: Re: method to parse date time stamp
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 31 Jan 2001 20:16:38 +0000
xslt parse date
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.