grokCV.xsl 5.8 KB
<xsl:stylesheet 
    xmlns:xsl  ="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:h    ="http://www.w3.org/1999/xhtml"
    xmlns:s    ="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:foaf ="http://xmlns.com/foaf/0.1/"
    xmlns:k    ="http://opencyc.sourceforge.net/daml/cyc.daml#"
    xmlns:card ="http://www.w3.org/2006/03/hcard#"
    xmlns:con  ="http://www.w3.org/2000/10/swap/pim/contact#"
    xmlns:usps ="http://www.w3.org/2000/10/swap/pim/usps#"
    xmlns:whois="http://www.kanzaki.com/ns/whois#"
    xmlns:cv   ="http://www.w3.org/2000/10/swap/pim/cv@@#"
    xmlns:r    ="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<div xmlns="http://www.w3.org/1999/xhtml">
<h2>Issue</h2>
<ul>
<li>hash-vs-slash in foaf</li>
</ul>
<address>$Id: grokCV.xsl,v 1.3 2006/07/12 21:44:09 connolly Exp $</address>
</div>

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

<xsl:template match="h:html">
  <r:RDF>
    <foaf:Document r:about="">
      <xsl:apply-templates />
    </foaf:Document>
  </r:RDF>
</xsl:template>

<xsl:template match="h:body">
  <xsl:for-each select='h:h1/*[@class="docClassName"]'>
    <r:type r:parseType="Resource">
      <s:label><xsl:value-of select='normalize-space(.)'/></s:label>
    </r:type>
  </xsl:for-each>

  <foaf:primaryTopic>
    <foaf:Person><!-- sometimes an org? -->
      <xsl:apply-templates mode="vcard-mode" select="."/>
      
      <xsl:for-each select='h:body/*[@class="affiliation"]'>
	<xsl:variable name='positionName'
		      select='normalize-space(*[@class="position"])'/>
	<xsl:variable name='orgName'
		      select='normalize-space(*[@class="org"])'/>
	<xsl:variable name='orgHome'
		      select='*[@class="org"]/h:a[@rel="aff"]/@href'/>
	
	<!-- hmm... use a cyc:PartProperty in stead? -->
	<!-- this construct takes us out of OWL DL -->
	<r:type>
	  <s:Class>
	    <s:label><xsl:value-of select='$positionName'/></s:label>
	    <cv:org r:parseType="Resource">
	      <s:label><xsl:value-of select='$orgName'/></s:label>
	      <foaf:homepage r:resource='{$orgHome}'/>
	    </cv:org>
	  </s:Class>
	</r:type>
      </xsl:for-each>
      
    </foaf:Person>
  </foaf:primaryTopic>
</xsl:template>

<xsl:template mode="vcard-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " vcard ")]'>
  <xsl:message>vcard mode: <xsl:value-of select="name()" /></xsl:message>
  <k:subAbstrac r:parseType="Resource">
    <xsl:apply-templates select="." mode="vcard-prop-mode" />
  </k:subAbstrac>
</xsl:template>


<xsl:template mode="vcard-prop-mode"
	      match='h:object[
		     contains(concat(" ", normalize-space(@class), " "),
		     " include ")
		     and substring(@data, 1, 1) = "#"]'>
  
  <xsl:message>vcard-prop-mode: include: <xsl:value-of select="name()" /></xsl:message>
  <xsl:variable name="target" select="substring(@data, 2)" />
  <xsl:apply-templates select="//*[@id = $target]" mode="vcard-prop-mode" />
</xsl:template>

<xsl:template mode="vcard-prop-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " fn ")]'>
  <xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
  <foaf:name>
    <xsl:value-of select="." />
  </foaf:name>
</xsl:template>

<xsl:template mode="vcard-prop-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " title ")]'>
  <xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>

  <card:title>
    <!-- textprop... @@abbr title, img alt, etc. -->
    <xsl:value-of select="." />
  </card:title>
</xsl:template>

<xsl:template mode="vcard-prop-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " url ")]'>
  <xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
  <xsl:variable name="ref">
    <xsl:choose>
      <xsl:when test='name() = "a" and @href'>
	<xsl:value-of select='@href' />
      </xsl:when>
      <xsl:otherwise>
	<xsl:value-of select='.' />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <!-- absolutize? -->
  <card:url r:resource="{$ref}" />
</xsl:template>

<xsl:template mode="vcard-prop-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " adr ")]'>
  <xsl:message>vcard-prop-mode: <xsl:value-of select="name()" /></xsl:message>
  <con:office>
    <usps:MailingLocation>
      <xsl:apply-templates select="." mode="adr-mode" />
    </usps:MailingLocation>
  </con:office>
</xsl:template>

<xsl:template mode="adr-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " street-address ")]'>
  <usps:deliveryAddress>
    <xsl:value-of select="normalize-space(.)" />
  </usps:deliveryAddress>
</xsl:template>

<xsl:template mode="adr-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " locality ")]'>
  <usps:cityName>
    <xsl:value-of select="normalize-space(.)" />
  </usps:cityName>
</xsl:template>

<xsl:template mode="adr-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " region ")]'>
  <usps:stateAbbr>
    <xsl:value-of select="normalize-space(.)" />
  </usps:stateAbbr>
</xsl:template>

<xsl:template mode="adr-mode"
	      match='*[
		     contains(concat(" ", normalize-space(@class), " "),
		     " postal-code ")]'>
  <usps:zipCode>
    <xsl:value-of select="normalize-space(.)" />
  </usps:zipCode>
</xsl:template>


<xsl:template name="findByClass"> <!-- @@dead code -->
  <xsl:param name="class" />

  <xsl:for-each select='
    descendant-or-self::*[
    contains(concat(" ", normalize-space(@class), " "),
    concat(" ", $class, " "))]'>
    <xsl:copy />
  </xsl:for-each>
</xsl:template>

<!-- don't pass text thru -->
<xsl:template match="text()" />
<xsl:template match="text()" mode="vcard-mode"/>
<xsl:template match="text()" mode="vcard-prop-mode" />
<xsl:template match="text()" mode="adr-mode" />

</xsl:stylesheet>