Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:35:16+00:00 2026-06-06T14:35:16+00:00

I am trying to swap the values for elements name and cmt in a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:35:17+00:00Added an answer on June 6, 2026 at 2:35 pm

    Use the Identity Transform with an override for those elements’ values:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:gpx="http://www.topografix.com/GPX/1/1">
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="gpx:name/text()">
            <xsl:value-of select="../../gpx:cmt/text()"/>
        </xsl:template>
        <xsl:template match="gpx:cmt/text()">
            <xsl:value-of select="../../gpx:name/text()"/>
        </xsl:template>
    </xsl:stylesheet>
    

    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:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:gpx="http://www.topografix.com/GPX/1/1">
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="gpx:name">
            <xsl:copy>
                <xsl:apply-templates select="@*|../gpx:cmt/text()"/>
            </xsl:copy>
        </xsl:template>
            <xsl:template match="gpx:cmt">
            <xsl:copy>
                <xsl:apply-templates select="@*|../gpx:name/text()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    This is a slightly more general solution, but the first is sufficient, given the input you’ve provided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to swap every pair of values in my array using for
I'm trying to swap two variables in ActionScript. I tried using: a = 42
I have a file format I'm trying to write to using C#. The format
I am trying to swap values in a 2D array, but I get an
I've been trying to find a way to swap option values between them while
Here I am trying to swap two characters in a string using XOR operation.
I am trying to swap out a hover image with javascript but it doesn't
I am trying to swap two LinearLayouts by setting their visibility properties to VISIBLE
I am trying to swap two adjacent nodes in a linked list, and I
I am trying to swap between array and pointer in c++ My code is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.