Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
XSLT stylesheet to translate WMATA Metrobus positions to KML

Get an API key from, and put it in

If you don't happen to have a web server running, but you do have Python, do the following:

  1. chmod +x
  2. chmod a+r bus.xslt
  3. mkdir cgi-bin
  4. mv bus.xslt cgi-bin
  5. python -m CGIHTTPServer 8001

The script will then be accessible at http://localhost:8001/cgi-bin/

Either way, open Google Earth, and select Add>Network Link. Enter the URL to the script, and set the refresh rate to at least 2 minutes.

These files are in the public domain.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:w="">
<xsl:template match="/">
<kml xmlns="">
<Style id="bus">
<name>Bus Positions</name>
<description>Near real-time positions for <xsl:value-of select="count(//w:BusPosition)" /> Metrobuses.</description>
<xsl:for-each select="//w:BusPosition">
<name>Bus <xsl:value-of select="w:VehicleID" /></name>
<description>Route <xsl:value-of select="w:RouteID"/> to <xsl:value-of select="w:TripHeadsign" /></description>
<coordinates><xsl:value-of select="w:Lon" />,<xsl:value-of select="w:Lat" /></coordinates>
dir=$(dirname $(which $0))
echo -e "Content-type: application/\n"
curl "${API_KEY}" 2>/dev/null | xsltproc "${dir}/bus.xslt" -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment