[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] GPX to XML?
Subject: Re: [xsl] GPX to XML? From: Michael Kay <mike@xxxxxxxxxxxx> Date: Thu, 6 Mar 2014 16:57:32 +0000 |
If you're using XSLT 2.0, add xpath-default-namespace="http://www.topografix.com/GPX/1/1" to the xsl:stylesheet element. If you're using 1.0, add a namespace declaration xmlns:gpx="http://www.topografix.com/GPX/1/1" and then prefix all unprefixed names in your XPath expressions and match patterns (throughout the styesheet) with "gpx:". Michael Kay Saxonica On 6 Mar 2014, at 16:44, Roger Price <rp272@xxxxxxxxx> wrote: > > > 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?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] GPX to XML?, Roger Price | Thread | [xsl] Yet another XSLT1 processor: , Дмитрий Грибов |
Re: [xsl] Streaming with XSLT versi, Michael Kay | Date | Re: [xsl] Streaming with XSLT versi, Eliot Kimber |
Month |