<xsl:stylesheet 
    xmlns:xsl  ="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:h    ="http://www.w3.org/1999/xhtml"
    xmlns      ="http://www.w3.org/1999/xhtml"
    xmlns:dc   ="http://purl.org/dc/elements/1.1/"
    xmlns:card ="mid:2000-07-12-vcardish-stuff@w3.org"
    xmlns:mtg  ="mid:2000-07-12-meeting-stuff@w3.org"
    xmlns:s    ="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:list ="http://www.w3.org/2000/07/23-lists#"
    xmlns:r    ="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<h:p>$Id: extract.xsl,v 1.6 2000/07/12 19:41:04 connolly Exp $</h:p>

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

<xsl:variable name="Empty" select='"http://www.w3.org/2000/07/23-lists#empty"'/>

<xsl:template match="h:html">
  <r:RDF>

  <xsl:apply-templates/>
  </r:RDF>
</xsl:template>

<xsl:template match="h:table[preceding-sibling::h:h2/h:a/@name = 'list']//h:tr[1]">

  <xsl:call-template name="extract-list"/>

</xsl:template>

<xsl:template name="extract-list">
  <xsl:param name="tailID"/>

  <xsl:choose>
	      <!-- find first item, checking for excused, full name -->
    <xsl:when test='following-sibling::h:tr[ not(contains(h:td[1], "*"))
				 and normalize-space(h:td[2])]'>

	      <!-- make that first tr the current node -->
      <xsl:for-each select='following-sibling::h:tr[ not(contains(h:td[1], "*"))
				 and normalize-space(h:td[2])][1]'>
	<xsl:variable name="listID"    select='concat("lst-", generate-id())'/>
        <xsl:variable name="meetingID" select='concat("mtg-", generate-id())'/>

        <xsl:if test="$tailID">
	  <r:Description about='{concat("#", $tailID)}'>
	    <list:rest r:resource="{concat('#', $listID)}"/>
	  </r:Description>
	</xsl:if>

        <list:List r:ID="{$listID}">
          <list:first r:resource='{concat("#", $meetingID)}'/>
	</list:List>

        <xsl:call-template name="describe-meeting">
          <xsl:with-param name="meetingID" select='$meetingID'/>
	</xsl:call-template>

	<xsl:call-template name="extract-list">
	  <xsl:with-param name="tailID" select="$listID"/>
	</xsl:call-template>
      </xsl:for-each>

    </xsl:when>

    <xsl:otherwise>

      <xsl:if test="$tailID">
        <r:Description about='{concat("#", $tailID)}'>
          <list:rest r:resource="{$Empty}"/>
        </r:Description>
      </xsl:if>

    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<xsl:template name="describe-meeting">
    <xsl:param name="meetingID"/>

    <xsl:variable name='excused' select='contains(h:td[1], "*")'/>
    <xsl:variable name='fullName' select="h:td[2]"/>
    <xsl:variable name='mailbox' select="h:td[4]/h:a/@href"/>
    <xsl:variable name='dates' select="h:td[5]"/>

    <xsl:if test="not($excused) and $fullName">

      <!-- this is about the meeting record, but we don't
      have its address handy@@ -->
      <!-- hmm... we're asserting the creator of
      the meeting record... would it be more direct
      to describe the scribe of the meeting?
      yes... using the date of the meeting record
      as the date of the meeting is iffy
      scribe(Meeting, Scribe) :- record(Meeting, Record), creator(Record, Scribe)
      -->
      <r:Description r:ID="{$meetingID}">

        <mtg:scribe>
	  <r:Description>
            <s:label><xsl:value-of select="normalize-space($fullName)"/></s:label>
	    <card:mailbox r:resource="{$mailbox}"/>
          </r:Description>
        </mtg:scribe>
        <mtg:date><xsl:value-of select="$dates"/></mtg:date>
      </r:Description>
    </xsl:if>

</xsl:template>

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


</xsl:stylesheet>
