I am trying to swap the values for elements name and cmt in a GPX file (XML) using an xslt.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="GPS TrackMaker" 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">
<metadata>
<link href="http://www.trackmaker.com">
<text>Geo Studio Tecnology Ltd</text>
</link>
<time>2012-06-29T21:53:25Z</time>
<bounds minlat="37.772562" minlon="-124.550080" maxlat="49.323978" maxlon="-122.404474"/>
</metadata>
<wpt lat="46.189580000" lon="-123.824460000">
<ele>0.000000</ele>
<name>G02010</name>
<cmt>Columbia River Maritime Museum</cmt>
<desc>Columbia River Maritime Museum</desc>
<sym>Museum</sym>
</wpt>
<wpt lat="46.189010000" lon="-123.824370000">
<ele>0.000000</ele>
<name>G02020</name>
<cmt>Marine Dr/17th St</cmt>
<desc>Marine Dr/17th St</desc>
<sym>Waypoint</sym>
</wpt>
</gpx>
After transformation:
...
<name>Columbia River Maritime Museum</name>
<cmt>G02010</cmt>
...
Can someone please show the correct xslt for this?
Thanks.
Use the Identity Transform with an override for those elements’ values:
Note that you could also match the elements directly (instead of their
text()) if your actual needs (or source input) are more complicated.That would look something like this:
This is a slightly more general solution, but the first is sufficient, given the input you’ve provided.