<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:h    ="http://www.w3.org/1999/xhtml"
  xmlns:r    ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:cal  ="http://www.w3.org/2002/12/cal/ical#"
  xmlns:dc   ="http://purl.org/dc/elements/1.1/"
  >

<xsl:output method="xml" indent="yes"/>

<xsl:template match="h:body">
  <r:RDF>
    <cal:Vcalendar>
      <xsl:apply-templates />
    </cal:Vcalendar>
  </r:RDF>
</xsl:template>

<xsl:template match="h:div">
  <xsl:variable
      name="mdy"
      select='normalize-space(substring-after(h:h2, ","))' />
  <xsl:variable
      name="y"
      select='normalize-space(substring-after($mdy, ","))'/>
  <xsl:variable
      name="d"
      select='normalize-space(substring-after(substring-before($mdy, ","), " "))'/>

  <xsl:variable name="m" select="3" /> <!-- @@hardcoded -->

  <xsl:variable
      name="date"
      select='concat(format-number("0000", $y),
	      "-", format-number($m, "00"),
	      "-", format-number($d, "00"))' />
  <xsl:for-each select="h:table/h:tbody">
    <xsl:variable name="desc" select="normalize-space(h:tr[1]/h:td[3])" />
    <xsl:variable name="place" select="normalize-space(h:tr[1]/h:td[4])" />

    <xsl:variable name="st" select="h:tr[1]/h:td[1]" />
    <xsl:variable name="stime"
		  select='concat(substring($st, 1, 2), ":",
                                 substring($st, 3, 2))'/>
    <xsl:variable name="et" select="h:tr[1]/h:td[2]" />
    <xsl:variable name="etime"
		  select='concat(substring($et, 1, 2), ":",
                                 substring($et, 3, 2))'/>

    <cal:component>
      <cal:Vevent>
	<cal:summary><xsl:value-of select="$desc" /></cal:summary>
	<cal:location><xsl:value-of select="$place" /></cal:location>
	<cal:dtstart r:parseType="Resource">
	  <cal:dateTime>
	    <xsl:value-of select='concat($date, "T", $stime)' />
	  </cal:dateTime>
	</cal:dtstart>
	<cal:dtend r:parseType="Resource">
	  <cal:dateTime>
	    <xsl:value-of select='concat($date, "T", $etime)' />
	  </cal:dateTime>
	</cal:dtend>
      </cal:Vevent>
    </cal:component>

    <!-- sessions -->
    <xsl:for-each select="h:tr[position() &gt; 1]">
      <xsl:variable name="where" select="normalize-space(h:td[6])" />
      <cal:component>
	<cal:Vevent>
	  <cal:summary>
	    <xsl:value-of select="h:td[3]" />
	    <xsl:text>: </xsl:text>
	    <xsl:value-of select="h:td[4]" />
	  </cal:summary>
	  <cal:description>
	    <xsl:value-of select="h:td[5]" />
	  </cal:description>
	  <cal:location><xsl:value-of select="$where" /></cal:location>

	  <cal:dtstart r:parseType="Resource">
	    <cal:dateTime>
	      <xsl:value-of select='concat($date, "T", $stime)' />
	    </cal:dateTime>
	  </cal:dtstart>
	  <cal:dtend r:parseType="Resource">
	    <cal:dateTime>
	      <xsl:value-of select='concat($date, "T", $etime)' />
	    </cal:dateTime>
	  </cal:dtend>
	</cal:Vevent>
      </cal:component>

    </xsl:for-each>

  </xsl:for-each>
</xsl:template>


<!-- don't pass text thru -->
<xsl:template match="text()|@*">
</xsl:template>

</xsl:transform>
