<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:rss="http://purl.org/rss/1.0/" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
xmlns:foaf="http://xmlns.com/foaf/0.1/" 
xmlns:skos="http://www.w3.org/2004/02/skos/core#" 
xmlns:admin="http://webns.net/mvcb/"
xmlns:xhtml="http://www.w3.org/1999/xhtml" 
xmlns:owl="http://www.w3.org/2002/07/owl#" 

xmlns:r="http:/www.purl.org/stuff/rev#" 
xmlns:hrev="http:/www.purl.org/stuff/hrev#" 

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

<xsl:template match="/">
  <rdf:RDF>
	<xsl:apply-templates select="xhtml:html/xhtml:body//*[contains(@class,'hreview')]"/>
  </rdf:RDF>
</xsl:template>


<xsl:template match="//*[contains(@class,'hreview')]">
  <r:Review>
	<xsl:apply-templates mode="hreview"/>
  </r:Review>
</xsl:template>

<xsl:template match="*" mode="hreview">
  <xsl:variable name="tag" select="local-name()" />
  <xsl:variable name="class" select="@class" />
  <xsl:variable name="field">
	<xsl:choose>
	  <xsl:when test="substring($class, string-length($class)-1)= 'fn'">
		<xsl:value-of select="substring($class, 1, string-length($class)-3)" />
	  </xsl:when>

	  <xsl:when test="substring($class, 1, 3)='fn'">
		<xsl:value-of select="substring($class, 3, string-length($class)+1)" />
	  </xsl:when>

	  <xsl:otherwise>
		<xsl:value-of select="$class" />
	  </xsl:otherwise>
	</xsl:choose>
  </xsl:variable>

	<!-- Class: "<xsl:value-of select="$class" />" --> 
	<!--  Field: "<xsl:value-of select="$field" />" -->
	<xsl:choose>
	  <xsl:when test="contains($field,'reviewer')">
		<r:reviewer>
		  <foaf:Person>
			<foaf:name><xsl:value-of select="descendant-or-self::*[contains(@class,'fn')]"/></foaf:name>
		  </foaf:Person>
		</r:reviewer>
	  </xsl:when>
	</xsl:choose>
	
	<xsl:choose>
	  <xsl:when test="contains($field,'item')">
		<r:target>
		  <rdf:Description>
		  	<xsl:if test="*[contains(@class,'url')]">
		  		<foaf:page rdf:resource="{*[contains(@class,'url')]/@href}"/>
		  	</xsl:if>
			<dc:title><xsl:value-of select="descendant-or-self::*[contains(@class,'fn')]"/></dc:title>
		  </rdf:Description>
		</r:target>
	  </xsl:when>
	</xsl:choose>
	
	
	<xsl:choose>
	  <xsl:when test="$field='description'">
		<dc:description><xsl:value-of select="." /></dc:description>
	  </xsl:when>
	</xsl:choose>
	
	<xsl:choose>
	  <xsl:when test="$field='rating'">
		<r:rating>
			<xsl:call-template name="procvalue">
				<xsl:with-param name="tag" select="$tag"/>
			</xsl:call-template>
		</r:rating>
	  </xsl:when>
	</xsl:choose>
	
	<xsl:choose>
	  <xsl:when test="$field='summary'">
		<dc:title><xsl:value-of select="." /></dc:title>
	  </xsl:when>
	</xsl:choose>
	
	<xsl:choose>
	  <xsl:when test="$field='dtreviewed'">
		<dc:date>
			<xsl:call-template name="procvalue">
				<xsl:with-param name="tag" select="$tag"/>
			</xsl:call-template>
		</dc:date>
	  </xsl:when>
	</xsl:choose>
	
	
	
	
	<xsl:apply-templates mode="hreview" /> 
	
</xsl:template>

<xsl:template match="text()" mode="hreview" />

<xsl:template name="procvalue">
	<xsl:param name="tag"/>
	<xsl:choose>
		<xsl:when test="$tag='abbr'">
			<xsl:value-of select="@title"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="."/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:transform>
