2 users online. Create an account or sign in to join them.Users

Search

A new XSLT utility, “Time Ago (Friendly)” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

Can you show how this is used?

It’s invoked by the following:

<xsl:call-template name="time-ago" />
    <xsl:with-param name="date-and-time" select="path/to/node" />
</xsl:call-template>

The path/to/node needs to be replaced with a date and time node from your xml output. How you reference this depends upon where you are in the node tree.

Thanks, this is really, really, really useful!

What if after "23 hours ago" I no longer wanted to display relative time and instead show standard date "3/7/2011". How would I do this?

this is how i did it, but someone may be able to suggest a better way

<xsl:variable name="time-ago">
    <xsl:call-template name="time-ago">
        <xsl:with-param name="date-and-time" select="date" />
    </xsl:call-template>
</xsl:variable>

<xsl:if test="not(contains($time-ago, 'hours') or contains($time-ago, 'minutes') or contains($time-ago, 'seconds'))">
    <xsl:value-of select="date" />
</xsl:if>

<xsl:if test="contains($time-ago, 'hours') or contains($time-ago, 'minutes') or contains($time-ago, 'seconds')">
    <xsl:value-of select="$time-ago" />
</xsl:if>

another way of doing it may be to simply test your target date against $today and if it's not today, use the original date, otherwise use time-ago

Technically designermonkey's code above has a small error with an extra slash in the first call-template. Took me a little while to figure that out, here is the corrected code:

<xsl:call-template name="time-ago">
    <xsl:with-param name="date-and-time" select="path/to/node" />
</xsl:call-template>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details