<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:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    >

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

<p>This transformation produces formalized minutes (actions, decisions, attendance) from XHTML meeting records, per <a
href="http://www.w3.org/2003/g/data-view">GRDDL</a>.</p>

<p>Participants go in a division class "roll".</p>

<p>Actions are elements with @class="action", starting with ACTION _aka_:</p>
<p>Decisions are elements with @class="resolved", with
objections in <tt>u</tt> and abstentions in <tt>em</tt>.</p>
 
<p>Using <a href="http://ontology.teknowledge.com/">SUMO</a> for terms
like Meeting, Resolution. Ugh... sumo:part is backwards (w.r.t. the
role noun convention.) Likewise sumo:names.</p>

<p>hmm... I have <a href="http://www.w3.org/2001/sw/schedScrape.xsl">code to scrape schedules to find people associated with events</a>...  boy... it's messy.
</p>

<address>
<a href="http://www.w3.org/People/Connolly/">Dan Connolly</a><br />
<small>$Id: groktagftf.xsl,v 1.2 2004/10/10 13:02:32 connolly Exp $</small>
</address>
</div>

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

<xsl:template match="h:html">
  <r:RDF>
    <r:Description r:about="">
      <rdfs:comment>@@ dc:source input doc, with title, last-mod</rdfs:comment>
    </r:Description>

    <sumo:FormalMeeting>
      <rdfs:comment>hmm... cyc:MeetingTakingPlace?
      http://xmlns.com/wordnet/1.6/Meeting
      </rdfs:comment>


      <!-- map page title to meeting name -->
      <k:nameString><xsl:value-of select="h:head/h:title"/></k:nameString>

      <rdfs:comment>@@hmm... foaf:page link to meeting page?</rdfs:comment>
      <rdfs:comment>@@date, place of the meeting</rdfs:comment>
      <rdfs:comment>@@meeting of ?GROUP</rdfs:comment>

      <xsl:variable name="roll" select='h:body//h:div[@class="roll"]'/>

      <xsl:call-template name="participants">
	<xsl:with-param name="roll" select='$roll'/>
      </xsl:call-template>

      <xsl:for-each select='h:body/h:div[@class = "minutes"]'>
	<xsl:call-template name="minutes">
	  <xsl:with-param name="roll" select='$roll'/>
	</xsl:call-template>
      </xsl:for-each>

    </sumo:FormalMeeting>
  </r:RDF>
</xsl:template>

<xsl:template name="participants">
  <xsl:param name="roll"/>

  <xsl:for-each select="$roll/h:ol/h:li">
    <k:socialParticipants>
      <r:Description r:nodeID='{generate-id()}'>
	<k:nameOfAgent><xsl:value-of select="h:b"/></k:nameOfAgent>
	<xsl:for-each select="h:i">
	  <k:nameOfAgent><xsl:value-of select="."/></k:nameOfAgent>
	</xsl:for-each>
	<rdfs:comment>@@ground the person in URI space somehow? foaf:mbox?
	   W3C account name?
	</rdfs:comment>
	<rdfs:comment>@@affiliation (connect to member org homepage)
	</rdfs:comment>
      </r:Description>
    </k:socialParticipants>
  </xsl:for-each>
</xsl:template>

<xsl:template name="who">
  <xsl:param name="roll"/>
  <xsl:param name="aka" />

  <xsl:for-each select="$roll/h:ol/h:li/h:i[
		normalize-space() = normalize-space($aka)]">
    <xsl:value-of select='generate-id(..)'/>
  </xsl:for-each>
</xsl:template>

<xsl:template name="minutes">
  <xsl:param name="roll"/>

  <!-- for each agendum...-->
  <xsl:for-each select="h:div">

    <xsl:variable name="heading" select='*[local-name()="h3"
			or local-name()="h4"]'/>
    <xsl:if test='not($heading)'>
      <xsl:message>cannot find heading for agendum</xsl:message>
    </xsl:if>

    <xsl:variable name="agendumID" select='generate-id()'/>

    <!-- an agendum is a subevent of the meeting (or containing agendum) -->
    <k:subEvents>
      <r:Description r:about='#{$heading/@id}'>
	<k:nameString>
	  <xsl:value-of select='$heading'/>
	</k:nameString>

	<!-- decisions -->
	<xsl:for-each select='.//h:strong[starts-with(., "RESOLVED")]'>
	  
	  <xsl:if test='generate-id(ancestor::h:div[1]) = $agendumID'>
	    <k:subEvents>
	      <sumo:Resolution r:nodeID='{generate-id()}'>
		<k:nameString><xsl:value-of select="."/></k:nameString>
		<rdfs:comment>@@ connect to the group making the decision</rdfs:comment>
		<rdfs:comment>@@ cite materials that are part of the decision</rdfs:comment>
		<mtg:abstentions r:parseType="Collection">
		  <xsl:for-each select="h:em">
		    <xsl:variable name="abstainer">
		      <xsl:call-template name="who">
			<xsl:with-param name="roll" select="$roll"/>
			<xsl:with-param name="aka" select="normalize-space()"/>
		      </xsl:call-template>
		    </xsl:variable>
		    <r:Description r:nodeID="{$abstainer}"/>
		  </xsl:for-each>
		</mtg:abstentions>
		<mtg:objections r:parseType="Collection">
		  <xsl:for-each select="h:u">
		    <xsl:variable name="abstainer">
		      <xsl:call-template name="who">
			<xsl:with-param name="roll" select="$roll"/>
			<xsl:with-param name="aka" select="normalize-space()"/>
		      </xsl:call-template>
		    </xsl:variable>
		    <r:Description r:nodeID="{$abstainer}"/>
		  </xsl:for-each>
		</mtg:objections>
	      </sumo:Resolution>
	    </k:subEvents>
	  </xsl:if>
	</xsl:for-each>

	<!-- actions -->
	<xsl:for-each select='.//h:strong[starts-with(., "ACTION")]'>

	  <xsl:if test='generate-id(ancestor::h:div[1]) = $agendumID'>

	    <!-- extract name -->
	    <xsl:variable name="aka"
			  select='normalize-space(substring-after(
			  substring-before(., ":"), "ACTION"))'/>
	    <xsl:variable name="whoID">
	      <xsl:call-template name="who">
		<xsl:with-param name="roll" select="$roll"/>
		<xsl:with-param name="aka" select="$aka"/>
	      </xsl:call-template>
	    </xsl:variable>

	    <xsl:if test='not(string-length($whoID))'>
	      <xsl:message>
		who is <xsl:value-of select='$aka'/>???
	      </xsl:message>
	    </xsl:if>

	    <k:subEvents>
	      <!-- actions seem to fit in sumo:Committing -->
	      <sumo:Committing r:nodeID='{generate-id()}'>
		<!-- @@grab text of the action -->
		<k:nameString><xsl:value-of select="."/></k:nameString>
		<sumo:agent r:nodeID='{$whoID}'/>
	      </sumo:Committing>
	    </k:subEvents>
	  </xsl:if>
	</xsl:for-each>

	<!-- nested items -->
	<xsl:call-template name="minutes">
	  <xsl:with-param name="roll" select='$roll'/>
	</xsl:call-template>
      </r:Description>
    </k:subEvents>

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

</xsl:transform>

