This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]