I am able to access the<trkpt></trkpt>
nodes by the xpath expression<xsl:for-each select='gpx/trk/trkseg/trkpt'>
when the GPX file has the following simple structure:
<gpx>
<trk>
<trkseg>
<trkpt lat="50.5324906" lon="7.0842605">
<ele>105.8824463</ele>
<time>2010-07-11T08:50:16Z</time>
</trkpt>
<trkpt lat="50.5323745" lon="7.0843524">
<ele>108.7662354</ele>
<time>2010-07-11T08:50:44Z</time>
</trkpt>
...
</trkseg>
</trk>
</gpx>
How can i achieve the same effect when namespaces are involved, e.g.:
<gpx xmlns="http://www.topografix.com/GPX/1/1"
creator="MapSource 6.15.11"
version="1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1
http://www.topografix.com/GPX/1/1/gpx.xsd">
The thing to remember is that a default namespace is not the same as a null namespace, and in xslt, not specifying a namespace in a path is a null namespace, NOT the default. ( The default namespace would be in effect for literals though, I believe. ) So in your xsl stylesheet, you need to specify the GPX namespace with a prefix and use that prefix in your paths:
You can also match using functions like local-name() in the path:
but generally it's better to use explicit namespaces.
In XSLT 1.0:
In XSLT 2.0:
So, you need to declare the namespace (prefix, URI) in your stylesheet and add this namespace in your QName test of XPath expression.
As example, this XSLT 1.0 stylesheet:
And this XSLT 2.0 stylesheet:
With this input:
Both output: