• 1 reply
  • Latest Post - ‏2007-11-28T20:02:45Z by SystemAdmin
17 Posts

Pinned topic Atom Feed from Google Calendar

‏2007-11-21T01:38:15Z |
Hi there

I've been redeveloping our school website as a "front-end," pulling Atom feeds from a variety of sources and transforming them via XSLT to keep the site looking consistent. Most of my XSLT has been learnt "on-the-fly" by examples on the web, and it's all going fine ...

... except for the Atom feed from Google Calendar. I've embedded the calendar in one of the pages using their IFRAME code, which works (tho' I don't really like IFRAMEs ... but I digress). On the front page, however, I grab a feed of the next three weeks' events, and use XSLT to produce the HTML. This is working -- however, I'd like to group events on the same day into a bulleted list, and this is where I'm having difficulty. I can grab each <event> and thus find the <title> and <gd:when> ... but how then do I group each event with a corresponding "when" entry?

Here is the code I'm using at the moment -- any comments/suggestions would be much appreciated.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"

<!--<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>-->
<xsl:output method="html" />

<xsl:template match="/atom:feed">
<xsl:apply-templates select="atom:entry" />
<xsl:template match="atom:entry" name="feed">
<xsl:variable name="myYear">
<xsl:value-of select="substring(gd:when/@startTime,1,4)" />
<xsl:variable name="myMonth">
<xsl:value-of select="substring(gd:when/@startTime, 6,2)" />
<xsl:variable name="myDay">
<xsl:value-of select="substring(gd:when/@startTime, 9,2)" />
<h2><xsl:value-of select="$myDay" />/<xsl:value-of select="$myMonth" />/<xsl:value-of select="$myYear" /></h2>
<li><a href="{atom:link[@rel='alternate']/@href}"><xsl:value-of select="atom:title" /></a></li>


Message was edited by: dave.hartley
Updated on 2007-11-28T20:02:45Z at 2007-11-28T20:02:45Z by SystemAdmin
  • SystemAdmin
    17 Posts

    Re: Atom Feed from Google Calendar

    Dave --

    Grouping is a problem that pops up frequently in XSLT processing. Fortunately, it IS possible. How complex it is depends on your requirements. You can use the "brute force" method, comparing every single element to every single other element to prevent duplicating effort, or you can use the Muenchian Method. (Both ways are chronicled in that link.)

    The "brute force" method is fine for smaller files, as I gather this one is, but if your processor supports keys it's worth looking into use the Meunchian method. If nothing else, it's an interesting twist on an old problem!

    Hope that helps...


    Message was edited by: Nicholas Chase
    Updated on 2007-11-28T20:02:45Z at 2007-11-28T20:02:45Z by SystemAdmin