From: Roger Price
Sent: Thursday, March 06, 2014 4:18 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: GPX to XML?
I have not touched XSLT since I retired. However I wish to convert some GPX
files to a different XML format for my sat nav. I remember how picky XSLT
can be...
Here is a simplified GPX source file:
<gpx xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creator="komoot gpx
writer" version="1.1"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<name>Tour</name>
<desc/>
<link href="http://www.komoot.de">
<text>komoot homepage</text>
<type>text/html</type>
</link>
</metadata>
<trk>
<name>Tour</name>
<trkseg>
<trkpt lat="50.749345" lon="-2.3432386">
<ele>53.85803985595703</ele>
<time>2014-03-03T22:10:21Z</time>
</trkpt>
<trkpt lat="50.7494596" lon="-2.3445584">
<ele>54.950225830078125</ele>
<time>2014-03-03T22:10:45Z</time>
</trkpt>
<trkpt lat="50.7494921" lon="-2.3439906">
<ele>53.61299514770508</ele>
<time>2014-03-03T22:10:32Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>
XSLT file:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<routing_points>
<default_set>
<xsl:for-each select="gpx/trk/trkseg/trkpt">
<xsl:choose>
<xsl:when test="position() =1">
<xsl:element name="departure">
<lon><xsl:value-of
select="floor(@lon*3600000)"/></lon>
<lat><xsl:value-of
select="floor(@lat*3600000)"/></lat>
</xsl:element>
</xsl:when>
<xsl:when test="position() = last()">
<xsl:element name="destination">
<lon><xsl:value-of
select="floor(@lon*3600000)"/></lon>
<lat><xsl:value-of
select="floor(@lat*3600000)"/></lat>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="waypoint">
<lon><xsl:value-of
select="floor(@lon*3600000)"/></lon>
<lat><xsl:value-of
select="floor(@lat*3600000)"/></lat>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</default_set>
</routing_points>
</xsl:template>
</xsl:stylesheet>
Result:
<routing_points>
<default_set/>
</routing_points>
However if I remove: xmlns="http://www.topografix.com/GPX/1/1" from the
<gpx> node I get what I need:
Modified Result:
<routing_points>
<default_set>
<departure>
<lon>-8438367</lon>
<lat>182698171</lat>
</departure>
<waypoint>
<lon>-8440411</lon>
<lat>182698054</lat>
</waypoint>
<destination>
<lon>-8440584</lon>
<lat>182697029</lat>
</destination>
</default_set>
</routing_points>
I feel that editing a source file first is a bit like cheating. Please can
anyone suggest what I should do?