Search

Awesome extension! Having problem selecting time with XLST though, would appreciate if someone could pass an experience eye across my issue.

<date-and-time>
        <date timeline="1" type="range">
         <start iso="2011-08-24T13:41:00+01:00" time="13:41" weekday="3" offset="+0100">2011-08-24</start>
         <end iso="2011-08-24T15:10:00+01:00" time="15:10" weekday="3" offset="+0100">2011-08-24</end>
       </date>
     </date-and-time>

From the XML above, I've selected the date succesfully, although when I target the time attribute (tested with node() and text() too) it shows the date (DD/MM/YYYY) instead of time.

<xsl:copy-of select="etc/date-and-time/date/start[@time]"/>

I can't quite understand why, should I being using an XSLT utility to format time and date instead of selecting attributes on the fly?

Try this:

<xsl:value-of select="etc/date-and-time/date/start/@time" />
<xsl:copy-of select="etc/date-and-time/date/start[@time]"/>

This will perform a copy of the element start that has an attribute time. If you want to get the value of the time attribute itself try a value-of:

<xsl:value-of select="etc/date-and-time/date/start/@time"/>

By the way, if you need advanced date and time formatting, Date and Time comes with a utility (datetime.xsl) and a data source (data.datetime.php) allowing localised formatting. Just import the utility into your templates and attach the data source to your pages.

Thanks for the speedy posts and help guys!

I just tried out date-format.xsl which has done the job nicely. Was interested to understand the problem as I did select using value-of too but with [@time].

Although, your suggestion below worked perfectly:

<xsl:value-of select="etc/date-and-time/date/start/@time" />

Was interested to understand the problem as I did select using value-of too but with [@time].

square brackets in an xpath query indicate a conditional predicate, so as nick said, you were selecting any start node that had an attribute time.

you can throw comparison operators in there to test for particular nodes, so to use your xml example, you could get all of the datetime nodes that occur on a tuesday with

<xsl:for-each select="etc/date-and-time/date/start[@weekday = 3]"/>

Thanks Fawx, its been an interesting learning curve with XSLT.

I added some new filters to the parseString function for what I need on a project:

// Tomorrow
elseif($string == 'tomorrow') {
    $start = $this->__getDate('tomorrow 00:00');
    $end = $this->__getDate('tomorrow 23:59');
}

// Latest
elseif($string == 'latest') {
    $now = new DateTime("now");             
    $start = $this->__getDate('today '.$now->format('H:i:s'));
    $end = $this->__getDate('2038-01-01');
}

// Latest today
elseif($string == 'latest-today') {
    $now = new DateTime("now");             
    $start = $this->__getDate('today '.$now->format('H:i:s'));
    $end = $this->__getDate('today 23:59');
}

start:latest will filter all entries which have a start time after the current time

end:latest - filters all entries which have not finished by current time. (This was useful for selecting the 'live event' in XSLT).

start:latest-today sets filter to entries which start by the end of the day. start:tomorrow - filters all entries starting tomorrow.

They are all working for me so please mention if you want them committed via Git, I'll be spending some time working with them today.

Thats pretty cool, at the moment I replicate a lot of that logic in XSLT. I have a feeling my usecase may be a little different though as I'm happy to pull all the entries in and group/display/highlight them as required.

Hey Brendo, thanks.

For some context, its an online radio station; so live show, next showing, todays entries and tomorrows entries.

I would be interested to see how your XSLT works, I had given up after trying to logically come up with a way to select the 'next showing', when the DS filter would only list all entries for the day.

One question: Is there a reason why you added these filters in the PHP and don't use the available to filter in the data source editor (prefixing with either start: or end:)?

tomorrow 00:00 to tomorrow 23:59
now to 2038-01-01
now to today 23:59

Or am I missing something essential?

Hey Nils,

I've confused myself by reading through the thread, I thought it wouldn't accept times, glad to help you clear up any confusion for the next person.

What you've recommended works great, thanks.

Is this the right way to do a range?

No, you are just adding two dates. There are two possible ways to add a range: Either select a second date in the calendar by holding down the shift key or hit the tab key when your in the start input field.

How can I display the correct date with XSL? I have the following situation:

  • I have an event that occurs every week
  • On my events-page I automaticly want to show the next date the event is.

I tried stuff like:

<xsl:variable name="date" select="my-date/date[start &gt; $today]" />

But that didn't do the trick. Anyone knows how to solve this?

Question first: Is there a reason why you don't filter your data source to only return the needed dates?

Answer second: You have to remove the hyphens from the dates to compare them properly, e. g. translate(start, '-', ''). So this should work:

<xsl:variable name="date" select="my-date/date[translate(start, '-', '') &gt; translate($today, '-', '')]" />

Answer first: yes, I filtered the dates, but the date/time-objects that have multiple dates caused an issue with this. So when I have dates like:

  • 01-09-2011
  • 08-09-2011
  • 15-09-2011
  • 22-09-2011

So when $today is 02-09-2011 I had to use the correct XSL to show date nr. 2 on my site instead of date nr. 1. And when the date is later than date nr.2 it should show date nr. 3 on the site.

This brings me to another problem I'm experiencing now: the sorting. I sort the datasource on the date-field, but it automaticly sorts on date nr. 1, regardless if the date has already passed. For example: If I have 4 dates (multiple) like:

01-09-2011
08-09-2011
15-09-2011

03-09-2011
06-09-2011
09-09-2011

15-09-2011

02-09-2011

They get sorted on date nr. 1, and I use XSLT to show the next occuring date according to $today (which is 02-09-2011 for this example). The result is then:

  • 08-09-2011 (because it gets sorted on 01-09-2011)
  • 02-09-2011
  • 03-09-2011
  • 15-09-2011

While the expected result should be:

  • 02-09-2011
  • 03-09-2011
  • 08-09-2011
  • 15-09-2011

Is there any solutions for this to sort correctly?

Answer second: that did the trick.

I now have the same problem when showing a single next event. I've sorted it on date, ascending, limit 1, but it doesn't ignore the dates that have already passed.

I have a vague feeling I understand the problem you are talking about. Could you please fill out a bug report on Github? Thanks!

Question deleted cos I'm a dumbass!

On another note:

Is it possible in one Date and Time entry to select individual days or mark them as reoccurring? i.e as with Kanduvisla's posts, he's got an event repeating every week.. how is the possible? I understand date range can be used, but I just want to set an event to occur once a week, but on certain days, as there are event holidays so there is no real consistency.

Any thoughts?

What if the day of the week was selectable?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details