Conversion KML -> fichier marqueur OSM

Le fichier KML étant au format XML, on utilise une transformation XSLT, ce qui permet de générer de façon très souple et avec très peu de rigidité de programmation le fichier TXT voulu:

La transformation en elle-même:

  $transform=
 '<?xml version="1.0" encoding=\'UTF-8\' ?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                  xmlns:k ="'.$namespaceuri.'">
   <xsl:output method="text" />
   <xsl:template match="/">
    <xsl:text>lat&#9;lon&#9;title&#9;description&#9;icon&#9;iconSize&#9;iconOffset</xsl:text>
    <xsl:apply-templates />
   </xsl:template>
   <xsl:template match="k:Document/k:name"></xsl:template>
   <xsl:template match="k:Style"></xsl:template>
   <xsl:template match="k:Folder/k:name"></xsl:template>
   <xsl:template match="k:Folder/k:Placemark[k:styleUrl=\'#lineStyle\']" ></xsl:template>
   <xsl:template match="k:Folder/k:Placemark[k:styleUrl=\'#camera\']" >
    <xsl:value-of select="substring-before(substring-after(./k:Point/k:coordinates,\',\'),\',\')" />
    <xsl:text>&#9;</xsl:text>
    <xsl:value-of select="substring-before(./k:Point/k:coordinates,\',\')" />
    <xsl:text>&#9;</xsl:text>
    <xsl:value-of select="./k:name" />
    <xsl:text>&#9;</xsl:text>

    <xsl:text>&lt;img src=</xsl:text>
    <xsl:value-of select="substring-before(substring-after(./k:description,\'href=\'), \' target\')" />
    <xsl:text> /&gt;&#9;</xsl:text>
    <xsl:value-of select="substring( substring-before( substring-after(./k:description,\'src=\'), \'/>\') ,2,string-length( substring-before( substring-after(./k:description,\'src=\'), \'/>\') )-2)" />

    <xsl:text>&#9;</xsl:text>
    <xsl:text>'.$marker_dim.'</xsl:text>
    <xsl:text>&#9;</xsl:text>
    <xsl:text>'.$marker_offset.'</xsl:text>
   </xsl:template>
  </xsl:stylesheet>';

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *