<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="http://www.w3.org/1999/xhtml"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:rs="http://www.w3.org/2001/sw/DataAccess/tests/result-set#"
  xmlns:res="http://www.w3.org/2001/sw/DataAccess/rf1/result"
  exclude-result-prefixes="rdf foaf dc rs res"
>

 <xsl:output method="html" indent="yes"/>

 <xsl:template name="notice">
 <!-- an explanatory message-->
  <div class="lead" style="margin-left:3em;margin-right:2em">
   <h2>Welcome and enjoy</h2>
   <p>This stylesheet is designed to pic up areas from an image based on SPARQL query results over RDF image annotation.</p>
  <rdf:RDF xmlns:cc="http://web.resource.org/cc/" xmlns:dcterms="http://purl.org/dc/terms/">
   <rdf:Description rdf:about="">
    <dc:description>This stylesheet is copyright (c) 2005 by Masahide Kanzaki.
   You can redistribute it and/or modify it under the terms of 
   the GPL (GNU General Public License) .</dc:description>
    <dcterms:modified>2005-05-21</dcterms:modified>
    <foaf:maker>
     <foaf:Person rdf:about="urn:pin:MK705" foaf:name="Masahide Kanzaki">
      <foaf:mbox rdf:resource="mailto:webmaster@kanzaki.com"/>
     </foaf:Person>
    </foaf:maker>
    <dc:rights>(c) 2005 by the author, copyleft under GPL</dc:rights>
    <cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/"/>
   </rdf:Description>
  </rdf:RDF>
  </div>
 </xsl:template>

 <xsl:template match="/">
  <xsl:apply-templates select="rdf:RDF/rs:ResultSet"/>
 </xsl:template>

 <!-- main data handling -->
 <xsl:template match="rdf:RDF/rs:ResultSet">
  <html>
   <head>
    <title>Image region XSLT presentation</title>
    <link rel="stylesheet" href="http://www.kanzaki.com/parts/kan01.css" type="text/css" />
    <script type="text/javascript" src="./areas.js">//</script>
   </head>
   <body onload="fixmoz();">
    <xsl:call-template name="banner"/>
    <h1>Image region XSLT presentation</h1>
    <xsl:apply-templates select="rs:solution"/>
    <xsl:call-template name="footer">
     <xsl:with-param name="cy">2005</xsl:with-param>
     <xsl:with-param name="status">Status: XSLT created 2005-05-10; modified 2005-05-21. Stylesheet copyleft under GPL.</xsl:with-param>
    </xsl:call-template>
   </body>
  </html>
 </xsl:template>


 <!-- RSS items -->
 <xsl:template match="rs:solution">
  <div class="resregion">
  <h2 id="r{position()}"><xsl:value-of select="rs:binding[rs:variable='title']/rs:value"/></h2>
  <xsl:variable name="coord" select="rs:binding[rs:variable='coords']/rs:value"/>
  <xsl:variable name="img" select="rs:binding[rs:variable='image']/rs:value/@rdf:resource"/>
  <xsl:variable name="desc" select="rs:binding[rs:variable='description']/rs:value"/>
  <xsl:variable name="tl" select="substring-before($coord,' ')"/>
  <xsl:variable name="br" select="substring-after($coord,' ')"/>
  <xsl:variable name="x" select="substring-before($tl,',')"/>
  <xsl:variable name="y" select="substring-after($tl,',')"/>
  <xsl:variable name="x2" select="substring-before($br,',')"/>
  <xsl:variable name="y2" select="substring-after($br,',')"/>
  <xsl:variable name="h" select="$y2 - $y"/>
  <xsl:variable name="w" select="$x2 - $x"/>
  <xsl:variable name="clip" select="concat('rect(', $y, 'px, ', $x2, 'px, ', $y2, 'px, ', $x, 'px', ')')"/>

  <p><xsl:attribute name="style"><xsl:value-of select="concat('height:',$h,'px;width:',$w,'px;overflow:hidden;margin-bottom:10px')"/></xsl:attribute>
   <img src="{$img}" alt=""><xsl:attribute name="style"><xsl:value-of select="concat('clip:', $clip, '; margin-top:-', $y, 'px; margin-left:-', $x, 'px; ', 'position:absolute;')"/></xsl:attribute></img>
  </p>
  <xsl:if test="$desc != ''"><p style="border:dotted 1px gray;padding:0.7em"><xsl:value-of select="$desc"/></p></xsl:if>
  <p>This is a region (<xsl:value-of select="$coord"/>) of the image at <a href="{$img}"><xsl:value-of select="$img"/></a>.</p>
  <var class="c"><xsl:value-of select="$clip"/></var>
  <var class="c">-<xsl:value-of select="$y"/></var>
  <var class="c">-<xsl:value-of select="$x"/></var>
  </div>
 </xsl:template>

 <xsl:include href="../../../parts/banner-footer.xsl"/>

</xsl:stylesheet>
