smart-home.xsl 7.7 KB
<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:foaf ="http://xmlns.com/foaf/0.1/"
    xmlns:k    ="http://opencyc.sourceforge.net/daml/cyc.daml#"
    xmlns:geo  ="http://opencyc.sourceforge.net/daml/cyc.daml#"
    xmlns:chrono="http://opencyc.sourceforge.net/daml/cyc.daml#"
    xmlns:pim  ="http://example/foo@@#"
    xmlns:con  ="http://www.w3.org/2000/10/swap/pim/contact#"
    xmlns:usps ="http://www.w3.org/2000/10/swap/pim/usps#"
    xmlns:map  ="http://www.w3.org/2000/10/swap/pim/earthMap#"
    xmlns:DubC ="http://purl.org/dc/elements/1.1/"
    xmlns:ss   ="http://www.w3.org/2001/sw/schedScrape?"
    xmlns:s    ="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:dt="http://www.w3.org/2001/XMLSchema#"
    xmlns:r    ="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<xsl:import href="../../2001/sw/schedScrape.xsl"/>

<div
    xmlns="http://www.w3.org/1999/xhtml">
<p>@@homePage, name, given, surname</p>

<p>@@foaf:interest, pubs, img, seeAlso</p>

<p>map @rel="organization" to <a href="http://xmlns.com/foaf/0.1/#term_workplaceHomepage">foaf:workplaceHomepage</a></p>

<address>$Id: smart-home.xsl,v 1.21 2006/01/29 22:19:02 connolly Exp $
</address>
</div>

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

<!-- @@GRDDL should pass the base addr as a param -->

<xsl:param name="subject"
	   select='"http://www.w3.org/People/Connolly/"'/>

<xsl:variable name="me" select='concat($subject, "#me")'/>

<xsl:template match="h:html">
  <r:RDF xml:base="{$subject}">


  <foaf:Person r:about="{$me}">

    <xsl:variable name="title"
		  select="/h:html/h:head/h:title"/>
    <xsl:variable name="mboxuri"
		  select='substring-before(//h:a[@rel="pubmbox1"]/@href, ",")'/>

    <con:mailbox r:resource='{$mboxuri}'/>
    <foaf:mbox r:resource='{$mboxuri}'/>

    <xsl:if test="$subject">
      <con:homePage>
        <r:Description r:about='{$subject}'>
	  <DubC:title><xsl:value-of select="$title"/></DubC:title>
	  <r:value>@@revision date</r:value>
        </r:Description>
      </con:homePage>

      <foaf:homepage>
        <r:Description r:about='{$subject}'>
	  <DubC:title><xsl:value-of select="$title"/></DubC:title>
	  <r:value>@@revision date</r:value>
        </r:Description>
      </foaf:homepage>
    </xsl:if>

    <xsl:for-each select=".//h:span[@class='given']">
      <con:givenName>
        <xsl:value-of select="."/>
      </con:givenName>
      <foaf:givenname>
        <xsl:value-of select="."/>
      </foaf:givenname>
    </xsl:for-each>

    <xsl:for-each select=".//h:span[@class='surname']">
      <con:familyName>
        <xsl:value-of select="."/>
      </con:familyName>
      <foaf:surname>
        <xsl:value-of select="."/>
      </foaf:surname>
    </xsl:for-each>

    <xsl:for-each select=".//h:h1">
      <foaf:name>
	<xsl:value-of select='normalize-space()'/>
      </foaf:name>
    </xsl:for-each>


    <xsl:for-each select='.//*[@class="nick"]'>
      <foaf:nick>
	<xsl:value-of select='normalize-space()'/>
      </foaf:nick>
    </xsl:for-each>


    <xsl:for-each select=".//h:a[@rel='organization']">
      <foaf:workplaceHomepage>
	<r:Description r:about='{@href}'>
	  <s:label><xsl:value-of select='.'/></s:label>
	</r:Description>
      </foaf:workplaceHomepage>
    </xsl:for-each>

    <xsl:for-each select=".//h:a[@rel='interest']">
      <foaf:interest>
	<r:Description r:about="{@href}">
	  <s:label><xsl:value-of select='normalize-space(.)'/></s:label>
	</r:Description>
      </foaf:interest>
    </xsl:for-each>

    <xsl:for-each select=".//h:a[@rel='publications']">

      <foaf:publications r:resource='{@href}'/>
    </xsl:for-each>

    <xsl:for-each select=".//h:img[@class='imgOfMe']">
      <foaf:img>
	<r:Description r:about='{@src}'>
	  <s:label><xsl:value-of select='@alt'/></s:label>
	</r:Description>
      </foaf:img>
    </xsl:for-each>

    <xsl:for-each select='.//h:link[@rel="seeAlso"]'>
      <s:seeAlso r:resource='{@href}'/>
    </xsl:for-each>

    <xsl:for-each select='.//h:a[@rel="seeAlso"]'>
      <s:seeAlso r:resource='{@href}'/>
    </xsl:for-each>

  </foaf:Person>

  <xsl:for-each select='.//h:dl[@class="eventLog"]/h:dd'> <!-- MAGIC -->
    <xsl:call-template name="eventDesc"/>
  </xsl:for-each>

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

<xsl:template name="each-property">
  <!-- produces a property element for each URI in a list -->

  <xsl:param name="objects"/>
  <xsl:param name="property"/>

  <xsl:choose>
    <xsl:when test="contains($objects, ' ')">
      <xsl:element name="{$property}">
        <xsl:attribute name="r:resource">
        <xsl:value-of select='substring-before($objects, " ")'/>
	</xsl:attribute>
      </xsl:element>

      <xsl:call-template name="each-property">
        <xsl:with-param name="objects"
    		    select='substring-after($objects, " ")'/>
        <xsl:with-param name="property" select="$property"/>
      </xsl:call-template>
    </xsl:when>

    <xsl:otherwise>
      <xsl:element name="{$property}">
        <xsl:attribute name="r:resource">
        <xsl:value-of select='$objects'/>
	</xsl:attribute>
      </xsl:element>
    </xsl:otherwise>

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


<xsl:template name="eventDesc">
  <xsl:variable name="when" select="preceding-sibling::h:dt[1]//text()"/>
  <xsl:variable name="where" select="preceding-sibling::h:dt[1]//h:b"/>

  <xsl:variable name="eventLabel" select="h:b"/>

  <xsl:message>
@@parsing event:
<xsl:value-of select="normalize-space($eventLabel)"/>: 
[<xsl:value-of select="$when"/>]
[<xsl:value-of select="$where"/>]
</xsl:message>

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

  <r:Description r:ID="{$eventID}">
    <k:socialParticipants r:resource="{$me}"/>

    <!-- a subevent for each meeting with somebody -->
    <!-- relate to foaf:knowsWell by events -->
    <xsl:for-each select="h:a[@rel='met']">
      <k:subEvents>
        <k:SocialOccurence>
          <k:socialParticipants r:resource="{$me}"/>
          <k:socialParticipants>
            <r:Description foaf:name='{normalize-space(.)}'>
              <foaf:page r:resource='{@href}'/>
            </r:Description>
          </k:socialParticipants>
        </k:SocialOccurence>
      </k:subEvents>
    </xsl:for-each>


    <s:label><xsl:value-of select='normalize-space($eventLabel//text())'/></s:label>

    <xsl:call-template name="ss:whenProps">
      <xsl:with-param name="when" select="$when"/>
    </xsl:call-template>

    <xsl:if test="$where">
      <xsl:call-template name="ss:whereProps">
        <xsl:with-param name="where" select="$where"/>
      </xsl:call-template>
    </xsl:if>


    <xsl:if test="$eventLabel/h:a">
      <foaf:homepage r:resource='{$eventLabel/h:a/@href}'/>
      <!-- hmm.. other sorts of links: for group meetings,
	   e.g. IETF meetings, link to the group home

           or: link to proceedings, rather that event home page

           maybe rather than foaf:homepage, I should just
	   say this is *some* page about the event
            -->

    </xsl:if>

    <!-- subevent for presentations -->
    <xsl:for-each select="h:cite/h:a">
      <k:subEvents>
        <k:Inform-CommunicationAct>
          <k:performedBy r:resource="{$me}"/>

          <k:infoTransferred r:resource="#ideas_{generate-id()}"/>
          <r:value> <!-- noop -->
            <k:TextualMaterial r:about='{@href}'>
              <DubC:title>
                <xsl:value-of select="normalize-space(.)"/>
              </DubC:title>
              <k:containsInformation r:resource="#ideas_{generate-id()}"/>
            </k:TextualMaterial>
          </r:value>
        </k:Inform-CommunicationAct>
      </k:subEvents>
    </xsl:for-each>
  </r:Description>
</xsl:template>

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


</xsl:stylesheet>