Skip to main content

developerWorks >  XML  >  Forums  >  Atom and RSS forum  >  developerWorks

Atom Feed from Google Calendar    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
This question is not answered.

Permlink Replies: 1 - Pages: 1 - Last Post: Nov 28, 2007 3:02 PM Last Post By: Nicholas Chase
dave.hartley

Posts: 1
Registered: Nov 20, 2007 03:39:22 AM
Atom Feed from Google Calendar
Posted: Nov 20, 2007 08:38:15 PM
 
Click to report abuse...   Click to reply to this thread Reply
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

Nicholas Chase

Posts: 127
Registered: Jun 29, 2005 08:37:22 PM
Re: Atom Feed from Google Calendar
Posted: Nov 28, 2007 03:01:00 PM   in response to: dave.hartley in response to: dave.hartley's post
 
Click to report abuse...   Click to reply to this thread Reply
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
 Tags
Help

Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular type of content or application that you're viewing.

My tags shows your tags for this particular type of content or application that you're viewing.

 

MoreLess 


Point your RSS reader here for a feed of the latest messages in all forums