Skip to content

Instantly share code, notes, and snippets.

@bitfyre
Created July 8, 2011 21:03
Show Gist options
  • Save bitfyre/1072815 to your computer and use it in GitHub Desktop.
Save bitfyre/1072815 to your computer and use it in GitHub Desktop.
Grouping by Month for a Symphony CMS Data Source Using Nils Hörrmann's Date and Time Field Extension
<!--
Snapshot of the XML I was working with.
-->
<event-listing>
<section id="21" handle="event">Event</section>
<entry id="100">
<city handle="city">City</city>
<date>
<date timeline="1" type="range">
<start iso="2011-07-06T00:00:00-05:00" time="00:00" weekday="3" offset="-0500">2011-07-06</start>
<end iso="2011-07-09T04:00:00-05:00" time="04:00" weekday="6" offset="-0500">2011-07-09</end>
</date>
</date>
<event-name handle="event-name-2">Event Name</event-name>
<state handle="US">US</state>
<url handle="http-wwwsiteorg">http://www.site.org/</url>
</entry>
<entry id="101">
<city handle="city-2">City 2</city>
<date>
<date timeline="1" type="range">
<start iso="2011-08-06T00:00:00-05:00" time="00:00" weekday="3" offset="-0500">2011-07-06</start>
<end iso="2011-08-09T04:00:00-05:00" time="04:00" weekday="6" offset="-0500">2011-07-09</end>
</date>
</date>
<event-name handle="event-name-2">Event Name 2</event-name>
<state handle="US">US</state>
<url handle="http-wwwsite2org">http://www.site2.org/</url>
</entry>
</event-listing>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Created by Alex Lemanski on 2010-05-17.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="../utilities/Master.xsl"/>
<!--
Include the Format Date/Time Advanced Utility
http://symphony-cms.com/download/xslt-utilities/view/20744/
-->
<xsl:import href="../utilities/Date-Time-Advanced.xsl"/>
<xsl:template match="data">
<article>
<xsl:for-each select="event-listing/entry">
<!--
this test checks the first 7 characters from the string of
`current()/date/date/start` and compares it with the one `event-item` node
and inserts the appropriate month information when they are different
-->
<xsl:if test="substring(current()/date/date/start, 1, 7) != substring(preceding-sibling::entry[1]/date/date/start, 1, 7)">
<h3>
<span>
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="current()/date/date/start"/>
<xsl:with-param name="format" select="'%m+; %y+;'"/>
</xsl:call-template>
</span>
</h3>
</xsl:if>
<article class='vevent'>
<h4 class='summary'><xsl:value-of select="event-name"/></h4>
<p class='dtstamp'>
<abbr class='dtstart' title='{date/date/start}'>
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="date/date/start"/>
<xsl:with-param name="format" select="'%m+; %d;%ds;'"/>
</xsl:call-template>
</abbr>
<xsl:if test="date/date/end != ''">
<xsl:text>-</xsl:text>
<abbr class='dtstart' title='{date/date/end}'>
<xsl:if test="substring(date/date/end, 6, 2) != substring(date/date/start, 6, 2)">
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="date/date/end"/>
<xsl:with-param name="format" select="'%m+;'"/>
</xsl:call-template>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:call-template name="format-date">
<xsl:with-param name="date" select="date/date/end"/>
<xsl:with-param name="format" select="'%d;%ds;'"/>
</xsl:call-template>
</abbr>
</xsl:if>
</p>
<p class='location'><xsl:value-of select="city"/>, <xsl:value-of select="state"/></p>
<p class='description'><a href='{url}' target='_blank'><xsl:value-of select="substring-after(url,'//')"/></a></p>
</article>
</xsl:for-each>
</div>
</article>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment