<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:c="http://s.opencalais.com/1/pred/">
<!--xmlns:fn="http://www.w3.org/2005/02/xpath-functions" -->
<xsl:variable name="urlPrefix" select="'http://s.opencalais.com/1'" />
<xsl:variable name="space" select="' '" />
<xsl:variable name="entity" select="'e'" />
<xsl:variable name="relation" select="'r'" />
<xsl:variable name="disambiguationUrlPrefix"><xsl:value-of select="$urlPrefix"/>/type/er</xsl:variable>
<xsl:variable name="resourceUrlPrefix"><xsl:value-of select="$urlPrefix"/>/type/em/</xsl:variable>
<xsl:variable name="resourceTypeOffset" select="string-length($resourceUrlPrefix)+1" />
<!--xsl:variable name="person"><xsl:value-of select="$entity"/>/Person</xsl:variable-->
<xsl:variable name="objectType"><xsl:value-of select="$urlPrefix"/>/type/sys</xsl:variable>
<xsl:variable name="relevance"><xsl:value-of select="$objectType"/>/RelevanceInfo</xsl:variable>
<xsl:variable name="instance"><xsl:value-of select="$objectType"/>/InstanceInfo</xsl:variable>
<!--xsl:variable name="test" select="fn:tokenize($instance, '/')" /-->
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="http://semanticproxy.opencalais.com/css/rdf.css" />
<script src="http://semanticproxy.opencalais.com/scripts/rdf.js"></script>
</head>
<body onload="formatEntries();">
<xsl:apply-templates />
<div id='entity' class='entity'/>
<div id='relation' class='relation'/>
</body>
</html>
</xsl:template>
<xsl:template match="rdf:Description">
<xsl:if test="starts-with(rdf:type/@rdf:resource,$resourceUrlPrefix)">
	<xsl:variable name="resourceTypePrefix" select="substring(rdf:type/@rdf:resource,$resourceTypeOffset,1)" />
	<xsl:variable name="resource"><xsl:value-of select="$resourceUrlPrefix"
		/><xsl:value-of select="$resourceTypePrefix"/>/</xsl:variable>
	<xsl:variable name="resourceType">
		<xsl:choose>
			<xsl:when test="$resourceTypePrefix=$entity">entity</xsl:when>
			<xsl:when test="$resourceTypePrefix=$relation">relation</xsl:when>
			<xsl:otherwise> </xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="rtype" select="substring-after(rdf:type/@rdf:resource,$resource)" />
	<xsl:variable name="divId" select="substring(@rdf:about,string-length(@rdf:about)-35,36)" />
	<div id="{$divId}" class="{$rtype} {$resourceType}Node" rtype="{$rtype}" eor="{$resourceTypePrefix}">
	<xsl:for-each select="node()">
	<xsl:if test="substring(name(.),1,2)='c:' and .!='N/A'">
	<span class="{substring-after(name(.),'c:')}">
	<xsl:if test="string-length(@rdf:resource)>0">
		<xsl:attribute name="res">y</xsl:attribute>
		<xsl:value-of select="substring(@rdf:resource,string-length(@rdf:resource)-35,36)" />
	</xsl:if>
	<xsl:if test="string-length(@rdf:resource)=0">
		<xsl:if test="name(.)='c:name' or 'c:position' or 'c:subject'">
			<xsl:attribute name="id">
			<xsl:value-of select="concat($divId,'Name')" />
			</xsl:attribute>
		</xsl:if>
		<xsl:value-of select="."/>
	</xsl:if>
	</span>
	</xsl:if>
	</xsl:for-each>
	</div>
</xsl:if>
<!--xsl:variable name="theAbout" select="@rdf:about" /-->
<xsl:if test="rdf:type/@rdf:resource=$relevance">
	<div>
	<xsl:attribute name="res">
	<xsl:value-of select="substring(c:subject/@rdf:resource,string-length(c:subject/@rdf:resource)-35,36)" />
	</xsl:attribute>
	<span class="relevance"><xsl:value-of select='format-number(c:relevance,"##.#%")' /></span>
	</div>
</xsl:if>
<xsl:if test="starts-with(rdf:type/@rdf:resource,$disambiguationUrlPrefix)">
	<xsl:variable name="disambiguationName" select="c:name" />
	<xsl:for-each select="node()">
		<xsl:if test="name(.)='c:subject'">
			<div>
			<xsl:attribute name="res">
			<xsl:value-of select="substring(@rdf:resource,string-length(@rdf:resource)-35,36)" />
			</xsl:attribute>
			<span class="disambiguation"><xsl:value-of select="$disambiguationName" /></span>
			</div>
		</xsl:if>
	</xsl:for-each>
</xsl:if>
<xsl:if test="rdf:type/@rdf:resource=$instance">
<xsl:if test="string-length(c:detection) > 0">
	<div class="InstanceInfo">
	<xsl:attribute name="res">
	<xsl:value-of select="substring(c:subject/@rdf:resource,string-length(c:subject/@rdf:resource)-35,36)" />
	</xsl:attribute>
	<span class="detection"><xsl:value-of select="c:detection"/></span>
	<!--span class="offset"><xsl:value-of select="c:offset"/></span>
	<span class="length"><xsl:value-of select="c:length"/></span-->
	</div>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
