I have an XML file with seminars that I would like to feed to google-calendar. The XML file is maintained by someone else and is updated regularly, so I would like to do this in a way that google automatically grabs these changes.
I don't have much experience with this kind of thing so I hope someone can point me in the right direction.
This is an example of the XML I want to process.
(XML file : "seminars.xml")
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="ical.xsl"?>
<seminars>
<lastupdate>20150707</lastupdate>
<seminar>
<speaker>A. Einstein</speaker>
<location>Zurich</location>
<date>20150607</date>
<time>15:45:00</time>
<university>Princeton</university>
<abstract>
<title>On the structure of generalized patent office spaces</title>
<content>To be announced.</content>
</abstract>
</seminar>
</seminars>
The most obvious way to achieve this, I would say, is using an XSLT style sheet which processes the XML and builds some file google-calendar can read. I have a website/server where I can put this XSL file so ideally I would hope to be able to do with just one upload of the right file.
The XSL sheet I have looks like this.
(XSL file: "ical.xsl")
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1" media-type="text/calendar"/>
<xsl:variable name="crlf"> </xsl:variable>
<xsl:template match="/">BEGIN:VCALENDAR<xsl:value-of select="$crlf"/>
CALSCALE:GREGORIAN<xsl:value-of select="$crlf"/>
VERSION:2.0<xsl:value-of select="$crlf"/>
SEQUENCE:1<xsl:value-of select="$crlf"/>
X-WR-TIMEZONE:Europe/Paris<xsl:for-each select="seminars/seminar"><xsl:value-of select="$crlf"/>
BEGIN:VEVENT<xsl:value-of select="$crlf"/>
LOCATION:<xsl:value-of select="location"/><xsl:value-of select="$crlf"/>
DTSTART:<xsl:value-of select="date"/>T154500<xsl:value-of select="$crlf"/>
DTEND:<xsl:value-of select="date"/>T164500<xsl:value-of select="$crlf"/>
DESCRIPTION:seminar by <xsl:value-of select="speaker"/><xsl:value-of select="$crlf"/>
SUMMARY:<xsl:value-of select="abstract/title"/><xsl:value-of select="$crlf"/>
END:VEVENT<xsl:value-of select="$crlf"/></xsl:for-each>
END:VCALENDAR<xsl:value-of select="$crlf"/>
</xsl:template>
</xsl:stylesheet>
This works if I process the XML file, pipe it to an iCal-file (xsltproc seminars.xml > mycal.ics
), and import it to some calendar in google-calendar.
The resulting mycal.ics
looks like this
BEGIN:VCALENDAR
CALSCALE:GREGORIAN
VERSION:2.0
SEQUENCE:1
X-WR-TIMEZONE:Europe/Paris
BEGIN:VEVENT
LOCATION:Zurich
DTSTART:20150607T154500
DTEND:20150607T164500
DESCRIPTION:seminar by A. Einstein
SUMMARY:On the structure of generalized patent office spaces
END:VEVENT
Now, the problem is that (1) google does not process the XML, thus generating an error upon importing and (2) I am not sure if this method would automatically "grab changes" since it would require reloading the XML occasionally.
So, is there a way to make google (or the webserver) process this file so it is recognized as an iCal file, and kept it up to date?
Finally a minor issue is also that the original XML has a different XSL file inside. Is there a simple way to make something like a symbolic link on my website to this file, or include the XML without the header so that I can just replace the original XSL with mine?
Click 'Import' Locate the CSV file you exported on your local computer. Select the correct calendar you want to import into (by default it will select your main calendar) Click Import.
The easiest solution is probably to create a CGI on your web server that converts from xml to ical. If your web server runs on Linux then the CGI can be so simple as the following file (I called it seminars
)
#!/usr/bin/sh
echo Content-type: text/calendar
echo
/usr/bin/xsltproc ical.xsl seminars.xml 2> /dev/null
This CGI script is processed by the Bourne shell. That's specified by the first line. The following 2 lines finalize the HTTP header with the media type (mime type) of ical calendars. The last line does the conversion using your XSLt transformation. Note that errors due to the processing instruction are ignored (redirected to /dev/null).
Note that your server must be configured to run CGIs. I tested it on Apache 2 and needed to
chmod 755 seminars # make CGI file executable
chmod . 711 # close directory to others (suexec)
I also created a .htacces$
file on the diretory to make sure the seminars
script is processed as a CGI
<Files seminars>
SetHandler cgi-script
</Files>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With