<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:blog="http://rdf.opiumfield.com/blog/0.1/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:doac="http://ramonantonio.net/doac/0.1/"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:misc="http://rdf.opiumfield.com/misc/0.1/"
  xmlns:movie="http://rdf.opiumfield.com/movie/0.1/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:visit="http://purl.org/net/vocab/2004/07/visit#"
  xmlns:wot="http://xmlns.com/wot/0.1/">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
  <xsl:template match="text()" />
  <xsl:template match="*[@rdf:about='#me']">
    <!-- selects triples with '#me' as subject -->
    <div>
      <h2>Friends</h2>
      <ul>
        <xsl:apply-templates mode="me" select="foaf:knows[@rdf:resource = ancestor::rdf:RDF/*[@rdf:about]/@rdf:about]">
          <xsl:sort select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:family_name" />
          <xsl:sort select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:name" />
        </xsl:apply-templates>
      </ul>
    </div>
  </xsl:template>
  <xsl:template match="foaf:knows" mode="me">
    <xsl:element name="li">
      <xsl:attribute name="class">
        <xsl:text>vcard</xsl:text>
        <xsl:if test="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource][foaf:gender = 'female']">
          <xsl:text> female</xsl:text>
        </xsl:if>
        <xsl:if test="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource][foaf:gender = 'male']">
          <xsl:text> male</xsl:text>
        </xsl:if>
      </xsl:attribute>
      <span class="fn">
        <xsl:value-of select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:name" />
      </span>
        <xsl:if test="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:homepage | ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:weblog">
          <div class="sites">
            Homepage(s):
        <ul>
          <xsl:apply-templates select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:homepage | ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/foaf:weblog" mode="friend" />
        </ul>      </div>
          
        </xsl:if>
    </xsl:element>
  </xsl:template>
  <xsl:template match="foaf:homepage | foaf:weblog" mode="friend">
    <li><a href="{@rdf:resource}"><xsl:value-of select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/dc:title" /></a></li>
  </xsl:template>
</xsl:stylesheet>

