Created
November 3, 2011 04:54
-
-
Save bzerangue/1335801 to your computer and use it in GitHub Desktop.
[XSLT] iCal utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
BEGIN:VCALENDAR | |
CALSCALE:GREGORIAN | |
X-WR-TIMEZONE;VALUE=TEXT:US/Central | |
METHOD:PUBLISH | |
PRODID:-//Park Cities Presbyterian Church\(PCA\)//iCal 1.0//EN | |
X-WR-CALNAME;VALUE=TEXT:Park Cities Presbyterian Church Events Feed | |
VERSION:2.0 | |
BEGIN:VEVENT | |
SEQUENCE:5 | |
DTSTART;TZID=US/Pacific:20021028T140000 | |
DTSTAMP:20021028T011706Z | |
SUMMARY:Coffee with Jason | |
UID:EC9439B1-FF65-11D6-9973-003065F99D04 | |
DTEND;TZID=US/Pacific:20021028T150000 | |
BEGIN:VALARM | |
TRIGGER;VALUE=DURATION:-P1D | |
ACTION:DISPLAY | |
DESCRIPTION:Event reminder | |
END:VALARM | |
END:VEVENT | |
END:VCALENDAR | |
--> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xCal="http://www.ietf.org/rfc/rfc2445.txt" xmlns:str="http://exslt.org/strings" extension-element-prefixes="xCal str"> | |
<xsl:strip-space elements="*"/> | |
<xsl:preserve-space elements="text"/> | |
<xsl:output method="text" media-type="text/calendar" encoding="utf-8"/> | |
<xsl:template match="/"> | |
<xsl:text>BEGIN:VCALENDAR
</xsl:text> | |
<xsl:text>PRODID:-//PCPC//NONSGML v.1.0//EN
</xsl:text> | |
<xsl:text>VERSION:2.0
</xsl:text> | |
<xsl:text>CALSCALE:GREGORIAN
</xsl:text> | |
<xsl:text>METHOD:PUBLISH
</xsl:text> | |
<xsl:text>X-WR-CALNAME:Events at Park Cities Presbyterian Church
</xsl:text> | |
<xsl:text>X-WR-TIMEZONE:US/Central
</xsl:text> | |
<xsl:apply-templates select="//entry" mode="VEVENTDETAIL" /> | |
<xsl:text>END:VCALENDAR
</xsl:text> | |
</xsl:template> | |
<xsl:template match="entry" mode="VEVENTDETAIL"> | |
<xsl:param name="start-date" select="translate(event-start-date,'-','')"/> | |
<xsl:param name="start-time" select="translate(event-start-date/@time,':','')"/> | |
<xsl:param name="end-date" select="translate(event-end-date,'-','')"/> | |
<xsl:param name="end-time" select="translate(event-end-date/@time,':','')"/> | |
<xsl:param name="lat-long"> | |
<xsl:call-template name="geocode"> | |
<xsl:with-param name="address" select="location-full-address"/> | |
</xsl:call-template> | |
</xsl:param> | |
<xsl:text>BEGIN:VEVENT
</xsl:text> | |
<xsl:text>SUMMARY:</xsl:text><xsl:value-of select="title" /><xsl:text>
</xsl:text> | |
<xsl:text>URL;VALUE=URI:</xsl:text><xsl:value-of select="concat('http://pcpc.org/events/',@id)" /><xsl:text>
</xsl:text> | |
<xsl:text>UID:</xsl:text><xsl:value-of select="concat($start-date,'T',$start-time,'00','-',@id)" /><xsl:text>@pcpc.org
</xsl:text> | |
<xsl:text>DESCRIPTION:</xsl:text><xsl:value-of select="title" /><xsl:text>
</xsl:text> | |
<!--><xsl:text>DTSTAMP:</xsl:text><xsl:value-of select="concat($start-date,'T',$start-time,'00')" /><xsl:text>
</xsl:text>--> | |
<xsl:text>LOCATION:</xsl:text> | |
<xsl:call-template name="escape-commas"> | |
<xsl:with-param name="text" select="location-full-address" /> | |
</xsl:call-template> | |
<xsl:text>
</xsl:text> | |
<xsl:text>GEO:</xsl:text><xsl:value-of select="translate($lat-long,', ',';')" /><xsl:text>
</xsl:text> | |
<!--<xsl:text>SEQUENCE:0
</xsl:text>--> | |
<!--><xsl:text>STATUS:CONFIRMED
</xsl:text>--> | |
<xsl:text>TRANSP:OPAQUE
</xsl:text> | |
<xsl:text>DTSTART;TZID=America/Chicago:</xsl:text><xsl:value-of select="concat($start-date,'T',$start-time,'00')" /><xsl:text>
</xsl:text> | |
<xsl:text>DTEND;TZID=America/Chicago:</xsl:text><xsl:value-of select="concat($end-date,'T',$end-time,'00')" /><xsl:text>
</xsl:text> | |
<!--><xsl:text>BEGIN:VALARM
</xsl:text> | |
<xsl:text>TRIGGER;VALUE=DURATION:-P1D
</xsl:text> | |
<xsl:text>ACTION:DISPLAY
</xsl:text>--> | |
<xsl:text>END:VEVENT
</xsl:text> | |
</xsl:template> | |
<xsl:template name="geocode"> | |
<xsl:param name="address"/> | |
<xsl:variable name="encodedAddress"> | |
<xsl:value-of select="translate($address,' ','+')"/> | |
</xsl:variable> | |
<xsl:variable name="urlString">http://maps.google.com/maps/geo?q=<xsl:value-of select="$encodedAddress"/>&output=xml&oe=utf8&sensor=false</xsl:variable> | |
<xsl:variable name="geocoder" select="document($urlString)"/> | |
<xsl:for-each select="$geocoder//*[name()='coordinates']"> | |
<xsl:if test="position() = 1"> | |
<xsl:value-of select="substring-after(substring-before(text(),',0'),',')"/><xsl:text>, </xsl:text><xsl:value-of select="substring-before(substring-before(text(),',0'),',')"/> | |
</xsl:if> | |
</xsl:for-each> | |
</xsl:template> | |
<!-- Escape single quotes --> | |
<xsl:template name="escape-single-quotes"> | |
<xsl:param name="text" /> | |
<xsl:variable name="apos">'</xsl:variable> | |
<xsl:variable name="bapos">\'</xsl:variable> | |
<xsl:value-of select="str:replace($text, $apos, $bapos)" /> | |
</xsl:template> | |
<!-- Escape double quotes --> | |
<xsl:template name="escape-double-quotes"> | |
<xsl:param name="text" /> | |
<xsl:variable name="apos">"</xsl:variable> | |
<xsl:variable name="bapos">\"</xsl:variable> | |
<xsl:value-of select="str:replace($text, $apos, $bapos)" /> | |
</xsl:template> | |
<!-- Escape commas --> | |
<xsl:template name="escape-commas"> | |
<xsl:param name="text" /> | |
<xsl:variable name="apos">,</xsl:variable> | |
<xsl:variable name="bapos">\,</xsl:variable> | |
<xsl:value-of select="str:replace($text, $apos, $bapos)" /> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment