<?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>Movies I've watched</h2>
      <ul>
        <xsl:apply-templates mode="me" select="movie:seen">
          <xsl:sort select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/dc:title[@xml:lang='en']" />
        </xsl:apply-templates>
        <!-- apply templates for the movie:seen element -->
      </ul>
    </div>
  </xsl:template>
  <xsl:template match="movie:seen" mode="me">
    <li>
      <a href="{@rdf:resource}"><xsl:value-of select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/dc:title[@xml:lang='en']" /></a>
      <!-- lookup url of resource, get English title -->
      <xsl:if test="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/movie:year">
        (<xsl:value-of select="ancestor::rdf:RDF/*[@rdf:about=current()/@rdf:resource]/movie:year" />)
      </xsl:if>
      <!-- if a year is specified, add that too -->
    </li>
  </xsl:template>
</xsl:stylesheet>
