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 3398250
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:37:35+00:00 2026-05-18T04:37:35+00:00

I have this xml: <pos:getPositionRouter xmlns:pos=positionNS> <positionID> <code>1</code> </positionID> <parameter>?</parameter> </pos:getPositionRouter> and I want

  • 0

I have this xml:

<pos:getPositionRouter xmlns:pos="positionNS">
   <positionID>
      <code>1</code>
   </positionID>
   <parameter>?</parameter>
</pos:getPositionRouter>

and I want to rename the element pos:getPositionRouter to x:getPosition using xslt:

<x:getPosition xmlns:x="newPositionNS">
   <positionID>
      <code>1</code>
   </positionID>
   <parameter>?</parameter>
</x:getPosition>

This is the sylesheet I came up with:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

 <xsl:param name="old_namespace" />
 <xsl:param name="old_element_localname" />
 <xsl:param name="new_namespace" />
 <xsl:param name="new_element_localname" />


 <xsl:template match="@*|node()">
  <xsl:choose>
   <xsl:when test="(local-name() = $old_element_localname) and (namespace-uri() = $old_namespace)">
    <xsl:element name="{$new_element_localname}" namespace="{$new_namespace}">
     <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
   </xsl:when>

   <!-- copy the rest as is -->
   <xsl:otherwise>
    <xsl:copy>
     <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

</xsl:stylesheet> 

I am forced to use xalan as xslt processor, and the output, unfortunately is this:

<getPosition xmlns="newPositionNS">
   <positionID xmlns:pos="positionNS">
      <code>1</code>
   </positionID>
   <parameter xmlns:pos="positionNS">?</parameter>
</getPosition>

The default namespace of the getPosition element becomes the new namespace, but the child elements should remain without namespace (xmlns="").

Can someone understand why?

Thank you!

  • 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-05-18T04:37:36+00:00Added an answer on May 18, 2026 at 4:37 am

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:param name="old_namespace" select="'positionNS'"/>
        <xsl:param name="old_element_localname" select="'getPositionRouter'"/>
        <xsl:param name="new_namespace_prefix" select="'x'"/>
        <xsl:param name="new_namespace" select="'newPositionNS'"/>
        <xsl:param name="new_element_localname" select="'getPosition'" />
        <xsl:template match="*">
            <xsl:choose>
                <xsl:when test="local-name()=$old_element_localname and
                                namespace-uri()=$old_namespace">
                    <xsl:element
                         name="{substring(concat($new_namespace_prefix,':'),
                                          1 div boolean($new_namespace_prefix))}{
                                $new_element_localname}"
                         namespace="{$new_namespace}">
                        <xsl:apply-templates select="@*|node()"/>
                    </xsl:element>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:element name="{name()}">
                        <xsl:apply-templates select="@*|node()"/>
                    </xsl:element>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template match="@*">
            <xsl:attribute name="{name()}">
                <xsl:value-of select="."/>
            </xsl:attribute>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <x:getPosition xmlns:x="newPositionNS">
        <positionID>
            <code>1</code>
        </positionID>
        <parameter>?</parameter>
    </x:getPosition>
    

    Note: If you want an specific prefix you should add it to the QName. If you want to remove in-scope namespace you shouldn’t use xsl:copy in XSLT 1.0

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

Sidebar

Related Questions

No related questions found

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.