<xsl:transform
    xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:h   ="http://www.w3.org/1999/xhtml"
    xmlns:r   ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:k   ="http://opencyc.sourceforge.net/daml/cyc.daml#"
    xmlns:sumo="http://reliant.teknowledge.com/DAML/SUMO.owl#"
    xmlns:mtg ="http://www.w3.org/2000/11/mr76/minutes#"
    xmlns:collab="http://www.w3.org/2000/10/swap/pim/collab@@#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:dc  ="http://purl.org/dc/elements/1.1/"
    xmlns:foaf ="http://xmlns.com/foaf/0.1/"
    xmlns:org  ="http://www.w3.org/2001/04/roadmap/org#"
    xmlns:c   ="http://www.w3.org/2002/12/cal/icaltzd#"
    >

<div xmlns="http://www.w3.org/1999/xhtml">

<p>This transforms an XHTML issues list into an RDF/XML formalized rendition, <a
href="http://www.w3.org/2003/g/data-view">GRDDL</a>.</p>

<address>
<a href="http://www.w3.org/People/Connolly/">Dan Connolly</a><br />
<small>$Id: grokIssues.xsl,v 1.12 2006/03/03 11:18:49 connolly Exp $</small>
</address>
</div>

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

<xsl:template match="h:html">
  <xsl:variable name="base" select='h:head/h:link[@rel="base"]/@href'/>
  <r:RDF xml:base='{$base}'>
  <org:Group>
    <foaf:homepage
	r:resource='{.//h:a[@rel="group"]/@href}'/>
    <foaf:made>
      <!-- an issues list is a calendar; aka a TODO list -->
      <c:Vcalendar r:about="">
      <!-- an issue starts with an h3 whose id is the same as its content-->
      <xsl:for-each select="h:body/h:div[h:h3 = h:h3/@id]">
	<xsl:variable name="issueID" select='h:h3/@id'/>
	<xsl:variable name="shortDesc" select='h:h3'/>

	<c:component>
	  <c:Vtodo r:about="#{$issueID}">
	    <foaf:name>
	      <xsl:value-of select="$shortDesc"/>
	    </foaf:name>
	    <c:summary>
	      <xsl:value-of select="$shortDesc"/>
	    </c:summary>
	    <xsl:for-each select='*/h:li[@class="accept"]'>
	      <xsl:variable name="when" select='substring-before(h:a, " ")'/>
	      <xsl:variable name="where" select='h:a/@href'/>

	      <xsl:if test='not($when)'>
		<xsl:message>
		  no accept date for <xsl:value-of select="$issueID"/>
		</xsl:message>
	      </xsl:if>

	      <c:created>
	        <xsl:value-of select='$when'/>
	      </c:created>
	      <foaf:page r:resource='{$where}'/>
	    </xsl:for-each>

	    <xsl:for-each select='*/h:li[@class="resolve"]'>
	      <xsl:variable name="when" select='substring-before(h:a, " ")'/>
	      <xsl:variable name="where" select='h:a/@href'/>

	      <c:status>COMPLETED</c:status>
	      <c:completed>
	        <xsl:value-of select='$when'/>
	      </c:completed>
	      <foaf:page r:resource='{$where}'/>
	    </xsl:for-each>

	    <xsl:for-each select='*/h:li[@class="owner"]'>
	      <xsl:variable name="who" select='substring-before(., " ")'/>
	      <xsl:variable name="when" select='substring-before(h:a, " ")'/>
	      <xsl:variable name="where" select='h:a/@href'/>
	      <collab:ownerDate>
	        <xsl:value-of select='$when'/>
	      </collab:ownerDate>
	      <foaf:page r:resource='{$where}'/>
	      <collab:ownerNick>
	        <xsl:value-of select='$who'/>
	      </collab:ownerNick>
	    </xsl:for-each>

	    <xsl:for-each select='*/h:li[@class="proposal"]'>
	      <xsl:message>kludging around cwm's lack of support for Literal parsetype</xsl:message>
	      <!--
	      <collab:proposal r:parseType="Literal">
		<xsl:copy-of select='.'/>
	      </collab:proposal>
	      -->
	      <collab:proposal>
		<xsl:value-of select='.'/>
	      </collab:proposal>
	    </xsl:for-each>

	    <xsl:for-each select='.//h:a[@rel="comment"]'>
	      <foaf:page r:resource="{@href}" /> <!-- assumed absolute -->
	    </xsl:for-each>
	  </c:Vtodo>
	</c:component>
      </xsl:for-each>
      </c:Vcalendar>
    </foaf:made>
  </org:Group>
  </r:RDF>
</xsl:template>


</xsl:transform>

