One of the most annoying omissions in Sharepoint 2007 is the inability to share calendars between sites and subsites:
- maintain a master calendar and view it (or part of it) in a subsite, or
- maintain a calendar in the subsite and “roll it up” with other subsite calendars to a master view in the main site.
Apparently this is rectified in Sharepoint 2010 but if you’re unable to upgrade, and aren’t allowed to build your own webparts, you’ve to look elsewhere for a solution:
- use a 3rd party webpart (can recommend the Bamboo Solutions offering having used it elsewhere), or
- hacking together via the page viewer webpart (I never got this to work but your mileage may vary)
However this article describes a 3rd option we implemented which met the requirement by not using calendars at all. Instead we used XML.
An XML solution in three parts
The XML solution allows a single, master, calendar to be published in multiple subsites, optionally filtering entries to particular subsets. To implement you need three elements:
- source calendar (in XML, not a SharePoint calendar)
- presentation/design code (XSL), and
- webpart that links the above two together on your site.
Without advanced CSS skills this won’t get you much more than an event list on any site. But if that’s all you want, and more important is the ability to reproduce that one list on multiple sites, then this approach might work for you.
Source calendar (XML)
In XML a calendar is simply a series of events, with varying parameters that include a date and a name, collected in a parent element. For our basic implementation we ended up with just that:
<calendar> <event> <date>12 August 2011</date> <title>Integration testing starts</title> </event> <event> <date>23 November 2011</date> <title>Integration testing ends</title> </event> ... </calendar>
To make it valid just add a definition on the first line:
<?xml version="1.0" standalone="no"?>
From this basis you can obviously add whatever other values you want to note for each event. For example if you want to present or filter by project, or responsibility, just add appropriate values to the XML.
presentation/design code (XSL)
The XSL code is what converts your XML into HTML that can be presented on your Sharepoint page. With the simple calendar schema adopted here this is only a few lines.
First set the scene:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ... </xsl:stylesheet>
Then add the XSL proper inside the above framework. The following code will first match our calendar parent element using
template-match, before traversing each of our events by using a
<xsl:template match="CALENDAR"> <table border="0"> <xsl:for-each select="EVENT"> <tr> <td><xsl:value-of select="title" /></td> <td><xsl:value-of select="date" /></td> </tr> </xsl:for-each> </table> </xsl:template>
This code puts each event (the “EVENT” elements) into a separate row in a table, with two event values “title” and “date” presented in separate columns.
This code gives you the basic framework for manipulating your XML. However XSL, and HTML/CSS are must more powerful than this example demonstrates. Feel free to research further on how to leverage this approach to really fine-tune the delivery of your calendar data.
For now, however, I will describe one of the most common XSL functions you’ll want in this solution: the ability to present a subset of your calendar entries based on a parameter recorded with each event.
In XSL you filter records by adding a comparison operator to your
for-each statement. For example, if we add a “project” attribute to our events, the code to filter to a specific project is a simple change to the
<xsl:for-each select="EVENT[project='Project A']">
This will now only list events that are for “Project A”. And how do you get entries to be categorised as “Project A” – just add to the XML:
<calendar> <event> <project>Project A</date> <date>12 August 2011</date> <title>Integration testing starts</title> </event> <event> <project>Project B</date> <date>23 November 2011</date> <title>Integration testing ends</title> </event> ... </calendar>
In this webpart you simply specify the XML and XSL you need to use. You can enter your details directly into the webpart (which negates the whole sharing theme for the XML, and can cause consistency issues with the XSL). Or you can link to external files. With the advantage that those files can exist anywhere in your site architecture.
Using XML to share a single calendar is not for everybody. It’s harder to maintain the entries, and the presentation is never going to be sexy. But as a quick way to stop yourself repeating yourself, it’s worth considering.