<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns="http://earth.google.com/kml/2.1"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <kml>
    <Document>
      <Style id="default">
        <IconStyle>
          <Icon>
            <href>root://icons/palette-4.png</href>
            <y>128</y>
            <w>32</w>
            <h>32</h>
          </Icon>
        </IconStyle>
        <LabelStyle><scale>0.7</scale></LabelStyle>
        <LineStyle><color>19010000</color><width>0.5</width></LineStyle>
        <PolyStyle><color>b03f85cd</color></PolyStyle>
      </Style>
      <xsl:apply-templates/>
    </Document>
    </kml>
  </xsl:template>

  <xsl:template match="sheet">
    <Folder>
      <name><xsl:value-of select="@name"/></name>
      <xsl:for-each select="row">
        <Placemark>
          <name><xsl:value-of select="cell[@col=0]"/></name>
          <description><xsl:value-of select="cell[@col=1]"/></description>
          <styleUrl>#default</styleUrl>
          <Point>
            <coordinates><xsl:value-of select="cell[@col=3]/@value"/>,<xsl:value-of select="cell[@col=2]/@value"/></coordinates>
          </Point>
        </Placemark>
        <xsl:variable name="row" select="@row - 1"/>
        <xsl:variable name="prev" select="../row[@row = $row]"/>
        <xsl:if test="$prev">
          <Placemark>
            <LineString>
              <tessellate>1</tessellate>
              <coordinates><xsl:value-of select="$prev/cell[@col=3]/@value"/>,<xsl:value-of select="$prev/cell[@col=2]/@value"/>,0 <xsl:value-of select="cell[@col=3]/@value"/>,<xsl:value-of select="cell[@col=2]/@value"/>,0</coordinates>
            </LineString>
          </Placemark>
        </xsl:if>
      </xsl:for-each>
    </Folder>
  </xsl:template>
</xsl:stylesheet>