<?xml version='1.0' encoding='iso-8859-1'?>

<!-- An XSLT style sheet to transform a Plazes (http://www.plazes.com/) 
     "Traces" XML file  into an XML file suitable for use with the
     Google Maps API. -->

<!--
	From the API documentation (http://www.google.com/apis/maps/documentation/):

 	Download the data in data.xml and load it on the map. The format we
	expect is:
	
	<markers>
		<marker lat="37.441" lng="-122.141"/>
		<marker lat="37.322" lng="-121.213"/>
	</markers>
	
	There's a sample data file at:
	
	http://www.google.com/apis/maps/documentation/data.xml
	
 -->

<!-- You can use TextXSLT to do the actual transformation, and you can get
 	 that at http://www.entropy.ch/software/macosx/ -->

<!-- Written by Peter Rukavina (http://www.ruk.ca/) 
	 (c) 2005 by Reinvented Inc.
	 License: http://creativecommons.org/licenses/by-sa/2.0/ca -->

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
	<xsl:output method="xml" indent="yes" />
	<xsl:output omit-xml-declaration="no" />
	<xsl:template match="travels">
		<markers>
			<xsl:apply-templates select="location" />
		</markers>
	</xsl:template>
	<xsl:template match="location">
		<xsl:element name="marker">
			<xsl:attribute name="lat">
				<xsl:variable name="lat" select="latitude"/>
				<xsl:variable name="latend" select="substring($lat, (string-length($lat) - 1) + 1)"/>
				<xsl:choose>
					<xsl:when test="$latend = 'N'">
						<xsl:value-of select="substring($lat, 1, (string-length($lat) - 1))"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat('-',substring($lat, 1, (string-length($lat) - 1)))"/>
					</xsl:otherwise>
				</xsl:choose>	        
			</xsl:attribute> 
			<xsl:attribute name="lng">
				<xsl:variable name="lng" select="longitude"/>
				<xsl:variable name="lngend" select="substring($lng, (string-length($lng) - 1) + 1)"/>
				<xsl:choose>
					<xsl:when test="$lngend = 'E'">
						<xsl:value-of select="substring($lng, 1, (string-length($lng) - 1))"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat('-',substring($lng, 1, (string-length($lng) - 1)))"/>
					</xsl:otherwise>
				</xsl:choose>	        
			</xsl:attribute> 
		</xsl:element> 
	</xsl:template>
</xsl:stylesheet>

