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	lon	title	description	icon	iconSize	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>	</xsl:text> <xsl:value-of select="substring-before(./k:Point/k:coordinates,\',\')" /> <xsl:text>	</xsl:text> <xsl:value-of select="./k:name" /> <xsl:text>	</xsl:text> <xsl:text><img src=</xsl:text> <xsl:value-of select="substring-before(substring-after(./k:description,\'href=\'), \' target\')" /> <xsl:text> />	</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>	</xsl:text> <xsl:text>'.$marker_dim.'</xsl:text> <xsl:text>	</xsl:text> <xsl:text>'.$marker_offset.'</xsl:text> </xsl:template> </xsl:stylesheet>';