views:

275

answers:

1

I am working with a XML driven CMS, and before I run off and either write or implement a module that parses the iCal format, I was wondering if there was any way to parse it using just XSLT or ideally just an XPath expression, as this is a built in function of the CMS.

+1  A: 

Well, your initial problem would be that it's not an XML format. iCalendar files are tagged text:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY;LANGUAGE="en_US":Bastille Day Party
END:VEVENT
END:VCALENDAR

So, parsing that with XPath and XSLT could be challenging. However, there is an XML representation of iCalendar. You can find information about in the xCal Basic spec. The example above (from that spec) looks like:

<?xml version="1.0" TODO_NAMESPACE="foo"?>
<iCalendar xmlns:xCal="urn:ietf:params:xml:ns:xcal">
    <vcalendar>
        <version>2.0</version>
        <prodid>-//hacksw/handcal//NONSGML v1.0//EN</prodid>
        <vevent>
            <dtstart>19970714T170000Z</dtstart>
            <dtendt>19970715T035959Z</dtend>
            <summary xml:lang="en_US">Bastille Day Party</summary>
        </vevent>
    </vcaledar>
</iCalendar

(I copied from the draft, hence the odd namespace). There's more information on the OASIS Coverpages site and on the CalConnect blog (that's the most up to date).

If you can convert from one to the other, then yes, you could parse it using XPath statements. If not, then you can parse the text. I'm not actually aware of any implementations I'm afraid.

Nic Gibson
Thanks for the response, it seems I'm stuck with just the normal iCal implementation I'm afraid. I did a little more digging and found this example http://designadmin.com/journal/2007/07/29/xslt-transformation-of-ics-to-xml/ In which the author seems to be converting iCal to XML, but I'm not quite sure how to implement it since there is no root XML element for the XSL.
Graham
If I have a little time, I'll take a look at that, looks interesting
Nic Gibson
@Graham - that looks like a good place to start. When you execute the stylesheet, pass in the string value for the iCal in the `ical-data-raw` parameter. You can run that XSLT against any XML file, even the XSLT itself. The templates work on the `ical-data-raw` parameter and don't do anything with the source XML doc.
Mads Hansen
@Mads - Thanks for the explanation that makes sense now that I've had more time to look through it. Unfortunately a limitation of the CMS I'm working with requires the data source to be valid XML before you can apply the XSLT to it. You can apply an XPath expression before it checks for well-formedness, and I was thinking I could use XPath to wrap some tags around the iCal text and then apply the XSLT but I'm an XPath neophyte and I'm not sure I can do that.
Graham
You will need to use something else to generate the XML doc that puts wrapping elements around the iCal text(e.g. php, jsp page that serves up dynamic XML). XPATH is used to address XML nodes, not to parse/transform. Are you not able to obtain the iCal text and set it as the XSLT parameter value? If so, then just use the XSLT as the source XML file to transform itself.
Mads Hansen
The iCal text is generated on another site so I only have access to it through a URL, so I guess I'm out of luck. Doing it in PHP isn't a big deal, I was just trying really hard to use the existing functionality of this CMS without resorting to building a new custom module for it, but I think I'm trying to change the core paradigm of this XML based CMS by not using an XML data source.If anyone is interested it's the Symphony CMS: http://symphony-cms.com/ (not to be confused with Symfony), It's actually a pretty cool system.
Graham