<xsl:transform
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0"
 xmlns      ="http://www.w3.org/1999/xhtml"
 xmlns:h    ="http://www.w3.org/1999/xhtml"
 xmlns:dc   ="http://purl.org/dc/elements/1.1/" 
 xmlns:foaf ="http://xmlns.com/foaf/0.1/"
 xmlns:geo  ="http://www.w3.org/2003/01/geo/wgs84_pos#"
 xmlns:org  ="http://www.w3.org/2001/04/roadmap/org#"
 xmlns:contact ="http://www.w3.org/2000/10/swap/pim/contact#"
 xmlns:r    ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 >

<!-- $Id: grokWho.xsl,v 1.8 2006/02/07 03:56:17 connolly Exp $ -->

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

  <xsl:param name="Base"
	     select='"http://www.w3.org/2001/sw/DataAccess/"'/>

  <xsl:template match="h:html">
    <!-- title/date scraping lifted from
	 group-scrape.xsl,v 1.4 2001/12/03 16:18:51
    -->
    <xsl:variable name="RCSDate"
		  select = 'normalize-space(substring-before(substring-after(
		  h:body/h:address,
		  concat("$", "Date:")), "$"))'/>
    <!-- convert yyyy/mm/dd hh:mm:ss to yyyy-mm-ddThh:mm:ssZ -->
    <xsl:variable name="ISODate"
		  select = 'concat(translate($RCSDate, "/ ", "-T"), "Z")'/>
    
    <r:RDF>
      <xsl:if test="$Base">
	<xsl:attribute name="xml:base">
	  <xsl:value-of select="$Base"/>
	</xsl:attribute>
      </xsl:if>
      <r:Description r:about="{$Base}">
	<dc:date><xsl:value-of select="$ISODate"/></dc:date>
	<dc:title><xsl:value-of select="h:head/h:title"/></dc:title>

	<foaf:primaryTopic>
	  <org:Group>
	    <!-- sigh... redundancy... -->
	    <foaf:homepage r:resource="{$Base}" />

	    <xsl:for-each select='h:body/h:div[h:h2/@id="who"]'>
	      <xsl:for-each select='h:ol/h:li/h:ul/h:li'>
		<org:member>
		  <xsl:call-template name="eachMember"/>
		</org:member>
	      </xsl:for-each>
	    </xsl:for-each>
	  </org:Group>
	</foaf:primaryTopic>
      </r:Description>

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



  <xsl:template name="eachMember">
    <xsl:variable name="surName" select='normalize-space(h:b)'/>
    <xsl:variable name="firstI"
		  select='concat(substring-before(., " "),
		  substring($surName, 1, 1))'/>
    <xsl:variable name="initials"
		  select='concat(substring(substring-before(., " "), 1, 1),
		  substring($surName, 1, 1))'/>
    
    <xsl:variable name="where" select='*[@class="geo"]'/>

    <xsl:if test='1'>
      <xsl:message>@@<xsl:value-of select='$firstI'/>: <xsl:value-of select='$surName'/> near <xsl:value-of select='$where'/><xsl:value-of select='$where'/>
      </xsl:message>
    </xsl:if>

    <foaf:Person r:ID='{$firstI}_Person'>
      <foaf:surName><xsl:value-of select='$surName'/></foaf:surName>
      <foaf:nick><xsl:value-of select='$firstI'/></foaf:nick>
      <foaf:workplaceHomepage r:resource="{../../h:a/@href}" />
      <xsl:if test="h:a[@rel='made']/@href">
	<foaf:made r:resource="{h:a[@rel='made']/@href}" />
      </xsl:if>

      <xsl:if test="$where">
	<xsl:variable name="latlon" select="$where/@title" />
	<xsl:variable name="lat" select='substring-before($latlon, ",")'/>
	<xsl:variable name="lon" select='substring-after($latlon, ",")'/>
	
	<foaf:based_near>
	  <r:Description>
	    <xsl:if test="$latlon">
	      <xsl:attribute name='r:about'>
		<xsl:text>#place_</xsl:text>
		<xsl:value-of select='$latlon'/>
	      </xsl:attribute>
	      <geo:lat><xsl:value-of select='$lat'/></geo:lat>
	      <geo:lon><xsl:value-of select='$lon'/></geo:lon>
	    </xsl:if>

	    <foaf:name>
	      <xsl:value-of select='normalize-space($where)' />
	    </foaf:name>
	  </r:Description>
	</foaf:based_near>
      </xsl:if>
    </foaf:Person>
  </xsl:template>

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

</xsl:transform>