<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=&quot;docClassName&quot;]">
    <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=&quot;affiliation&quot;]">
	<xsl:variable name="positionName" select="normalize-space(*[@class=&quot;position&quot;])"/>
	<xsl:variable name="orgName" select="normalize-space(*[@class=&quot;org&quot;])"/>
	<xsl:variable name="orgHome" select="*[@class=&quot;org&quot;]/h:a[@rel=&quot;aff&quot;]/@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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; vcard &quot;)]">
  <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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; include &quot;)        and substring(@data, 1, 1) = &quot;#&quot;]">
  
  <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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; fn &quot;)]">
  <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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; title &quot;)]">
  <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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; url &quot;)]">
  <xsl:message>vcard-prop-mode: <xsl:value-of select="name()"/></xsl:message>
  <xsl:variable name="ref">
    <xsl:choose>
      <xsl:when test="name() = &quot;a&quot; 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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; adr &quot;)]">
  <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(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; street-address &quot;)]">
  <usps:deliveryAddress>
    <xsl:value-of select="normalize-space(.)"/>
  </usps:deliveryAddress>
</xsl:template>

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

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

<xsl:template mode="adr-mode" match="*[        contains(concat(&quot; &quot;, normalize-space(@class), &quot; &quot;),        &quot; postal-code &quot;)]">
  <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(&quot; &quot;, normalize-space(@class), &quot; &quot;),     concat(&quot; &quot;, $class, &quot; &quot;))]">
    <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>