<?xml-stylesheet href="http://www.w3.org/StyleSheets/base.css" type="text/css"?><?xml-stylesheet href="http://www.w3.org/2002/02/style-xsl.css" type="text/css"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" exclude-result-prefixes="html">

<!-- Output method XML -->
<xsl:output method="text" 
  indent="yes"
  encoding="utf-8" 
  />

<!-- @@@ Replace this key with your Google Map API Key
     See http://www.google.com/apis/maps 
-->
  <xsl:param name="googleKey" select="'ABQIAAAAPDJmehN7nkvWmZE_H-l3yxRbyUrAdDyJZt0oLbHlmvQLMn8dmRTOYJJ3KNujnQpQo3t3sjQ1Fq66Rw'"/>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="http://www.w3.org/StyleSheets/base"/>
    <title>Photomap spider</title>
  </head>
  <body>
    <h1>Photomap spider</h1>

    <p>This XSLT style sheet parses an XHTML page, spiders links from it <!-- to a parametrizable depth (<code>depth</code> parameter) @@@notyet -->, and create a javascript script that, when included in an HTML page, generates a geographic map of the site using Google Maps (enabled with a key given as <code>googleKey</code> parameter) with links for each page which contains Geographical data.</p>
    <p>(This presumes that all the pages spidered are XHTML well-formed)</p>

    <p class="copyright">Copyright &#169; 2006 <a href="http://www.w3.org/">World Wide Web Consortium</a>, (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of
Technology">M.I.T.</acronym></a>, <a
href="http://www.ercim.org/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio University</a>). All Rights
    Reserved. http://www.w3.org/Consortium/Legal/. W3C <a href="http://www.w3.org/Consortium/Legal/copyright-software">software licensing</a> rules apply.</p>
    <address><a href="http://www.w3.org/People/Dom/">Dominique Haza&#235;l-Massieux</a> - $Id: basic.xsl,v 1.5 2005/06/15 10:30:10 dom Exp $</address>
    </body>
</html>


<xsl:template match="/">
  <xsl:text>

            var map = new GMap(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.centerAndZoom(new GPoint(0, 0), 15);
            
            // Create a marker whose info window displays the given text.
            function createMarker(point, dir, icon, text) {
            var marker = new GMarker(point);
            var longi = new String(point.x);
            var lat = new String(point.y);
            var idName= "p" + longi.replace('.','_').replace('-','_') + '_' + lat.replace('.','_').replace('-','_') ;
            if (!document.getElementById(idName)) {
                var span  = document.createElement('ul');
                span.id = idName;
                mapElt = document.getElementById("map");
                mapElt.appendChild(span);
            } else {
                var span = document.getElementById(idName);
            }
            var link = document.createElement('a');
            var item = document.createElement('li');
            link.href=dir
            link.appendChild(document.createTextNode(text));
            item.appendChild(link);
            span.appendChild(item); 
            GEvent.addListener(marker, 'click', function() {
            marker.openInfoWindow(span);
            });
            return marker;
            }
            
            // one marker for each photo album, indicating lat,lon,directory name,icon filename
            // automatically generated from photos.html
  </xsl:text>
            <xsl:apply-templates select="descendant::html:a[not(contains(@href,':'))]"/>
</xsl:template>

<xsl:template match="html:a">
  <xsl:variable name="geo" select="document(@href)/html:html/html:head/html:meta[@name='ICBM' and contains(@content,',')]/@content" />
  <xsl:if test="normalize-space($geo)">
    <xsl:message>spidering <xsl:value-of select="@href"/></xsl:message>
    <xsl:value-of select="concat('map.addOverlay(createMarker(new GPoint(',substring-after($geo,','),',',substring-before($geo,','),'),&quot;',@href,'&quot;,&quot;&quot;,&quot;',document(@href)/html:html/html:head/html:title,'&quot;));&#xa;')"/>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

