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

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"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gd="http://schemas.google.com/g/2005"
>

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

</xsl:stylesheet>

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

    Re: Atom Feed from Google Calendar

    ‏2007-11-28T20:02:45Z  in response to SystemAdmin
    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...

    Nick

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