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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:00:30+00:00 2026-06-04T16:00:30+00:00

How do I only add a namespace to the root element? My XML: <Envelope>

  • 0

How do I only add a namespace to the root element?

My XML:

<Envelope>
    <from>
        <contents />
    </from>
</Envelope>

My desired output:

<Envelope xmlns:tns="Foo">
    <from>
        <contents />
    </from>
</Envelope>

I can only get “xmlns=’Foo'” using this, not “xmlns:tns=..”:

<xsl:element name="{local-name()}" namespace="Foo" >
        <xsl:copy-of select="attribute::*"/>
        <xsl:apply-templates />
</xsl:element>
  • 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-04T16:00:31+00:00Added an answer on June 4, 2026 at 4:00 pm

    Here is a complete transformation:

    <xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:tns="Foo">
         <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="{name()}">
           <xsl:copy-of select=
            "document('')/*/namespace::*[name()='tns']"/>
           <xsl:apply-templates/>
          </xsl:element>
         </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <Envelope>
        <from>
            <contents />
        </from>
    </Envelope>
    

    the wanted, correct result is produced:

    <Envelope xmlns:tns="Foo">
       <from>
          <contents/>
       </from>
    </tns:Envelope>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have only one namespace in my XML file, defined on the root element.
I would like to add a namespace prefix to the XML root node and
Since Postgres can only add columns at the end of tables, I end up
How can I add a css file to only a child page while using
There is a schema with the following boring root element: <?xml version=1.0 encoding=utf-8?> <xs:schema
how can i add namespace name before a attribute of newly created tag,like <Data
I want have the following output: <?xml version=1.0 encoding=UTF-8?> <structure:structuralDataRoot xmlns:register=http://www.test.ch/register/1 xmlns:structure=http://test.ch/structure/1 > <structure:tester>ZH</structure:tester>
we use an external Database where we cant edit table designs only add own
What if I want not only to add events for all future added, but
I have few nested DIVs at page. I want to add event only for

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.