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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:49:19+00:00 2026-06-13T04:49:19+00:00

My problem is how to add namespace and prefix for all elements and attributes

  • 0

My problem is how to add namespace and prefix for all elements and attributes using XSLT?
My input xml as is….

<ProcessCreditMemo xmlns='CreditMemo' 
                   xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                   xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<ORDER_HEADERDetails>
    <ORDER_HEADER>
    <NAME>0010185214</NAME>

to be…

<ns0:ProcessCreditMemo xmlns='CreditMemo' 
                       xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
                       xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                       xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' 
                       xmlns:ns0="http://tempuri.org/">
<ns0:ORDER_HEADERDetails>
    <ns0:ORDER_HEADER>
   <ns0:NAME>0010185214</NAME>

I need add the prefix “ns0:” for all elements and attributes, and add the namespace “xmlns:ns0=”http://tempuri.org/&#8221; in the header “ProcessCreditMemo”.

I am trying to build a XSLT to do it…

<xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()|text()|@*">
    <xsl:copy>
        <xsl:if test="local-name()='ProcessCreditMemo'">
            <xsl:attribute name="xmlns" namespace="http://tempuri.org/" />
        </xsl:if>

but the resulting XML duplicates the prefix with empty value.

<ProcessCreditMemo xmlns="CreditMemo" 
                   xmlns:ns0="http://tempuri.org/" 
                   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   ns0:xmlns="">
  • 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-13T04:49:21+00:00Added an answer on June 13, 2026 at 4:49 am

    This transformation:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ns0="http://tempuri.org/">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="*">
      <xsl:element name="ns0:{name()}" namespace="http://tempuri.org/">
       <xsl:copy-of select="namespace::*"/>
           <xsl:apply-templates select="node()|@*"/>
      </xsl:element>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the (corrected) provided input (severely malformed, incomplete XML):

    <ProcessCreditMemo xmlns='CreditMemo'
      xmlns:xsd='http://www.w3.org/2001/XMLSchema'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
      <ORDER_HEADERDetails>
        <ORDER_HEADER>
          <NAME>0010185214</NAME>
        </ORDER_HEADER>
      </ORDER_HEADERDetails>
    </ProcessCreditMemo>
    

    produces the wanted, correct result (not the severely malformed/incomplete provided wanted-result):

    <ns0:ProcessCreditMemo xmlns:ns0="http://tempuri.org/" xmlns="CreditMemo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <ns0:ORDER_HEADERDetails>
          <ns0:ORDER_HEADER>
             <ns0:NAME>0010185214</ns0:NAME>
          </ns0:ORDER_HEADER>
       </ns0:ORDER_HEADERDetails>
    </ns0:ProcessCreditMemo>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add a namespace prefix to the XML root node and
I add this problem for quite some time when using NetBeans. Recently I add
NOTE I am limited to .NET 2.0 I need to add a namespace using
I'm using VB 2008 and I'm trying to add a xmlns=mynamespace attribute to an
Im using routes.add instead of routes.maproute (which has a namespace arg) because I extended
#include<iostream> using namespace std; class base { public: virtual void add() { cout <<
I have problem to add jQuery to some existing code, please help. We have
Got a problem with my add function to my database. The following code hangs
I have a problem: I've add a Jquery UI drag-n-drop widget to my page,
Problem: I want to add headers in the middle of a gridview databind. I

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.