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

  • Home
  • SEARCH
  • 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 1003847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:02:24+00:00 2026-05-16T08:02:24+00:00

So I have an input file that uses my company’s namespace in the default

  • 0

So I have an input file that uses my company’s namespace in the default namespace (xmlns="companyURL") but I want my output file to use something other than the default namespace (xmlns:cmp="companyURL"). So I construct my file using the cmp namespace, but then I want to copy some of the inner elements:

<xsl:element name="cmp:container">
  <xsl:for-each select="foo">
    <xsl:copy-of select="." />
  </xsl:for-each>
</xsl:element>

Unfortunately, what this does is define the default namespace for each of those inner elements, making the file incredibly verbose and ugly. Simplified example:

Source:

<foo xmlns="companyURL">
  <num1>asdf</num1>
  <num2>ghjkl</num2>
</foo>

Turns into:

<cmp:container xmlns:cmp="companyURL">
  <num1 xmlns="companyURL">asdf</num1>
  <num2 xmlns="companyURL">ghjkl</num2>
</cmp:container>

Of course, companyURL is big and long and ugly, and it’s the same in both places, so I would prefer the above result to just be the following:

<cmp:container xmlns:cmp="companyURL">
  <cmp:num1>asdf</cmp:num1>
  <cmp:num2>ghjkl</cmp:num2>
</cmp:container>

Is there an easy way to do this, or should I convert everything under the cmp namespace to the default namespace? I would prefer to use the explicit namespace naming if possible, it aids in understanding the XSLT in my experience.

  • 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-16T08:02:25+00:00Added an answer on May 16, 2026 at 8:02 am

    This transformation:

     <xsl:template match="*">
         <xsl:element name="cmp:{name()}" namespace="CompanyURL">
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates/>
         </xsl:element>
     </xsl:template>
     <xsl:template match="/*">
         <cmp:container xmlns:cmp="CompanyURL">
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates/>
         </cmp:container>
     </xsl:template>
    </xsl:stylesheet>
    

    when performed on the provided XML document:

    <foo xmlns="companyURL">
      <num1>asdf</num1>
      <num2>ghjkl</num2>
    </foo>
    

    produces the wanted, correct result:

    <cmp:container xmlns:cmp="CompanyURL">
       <cmp:num1>asdf</cmp:num1>
       <cmp:num2>ghjkl</cmp:num2>
    </cmp:container>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a perl program that takes input and output file arguments, and I'd
I current have a JFrame application that uses JTextField's for input of file location
Please help with the following: I have an input file that is quite heterogeneous
I have a php file that contains a form (which contains 2 input boxes
I have a program that reads input from a file. I am trying to
I have a linux utility that parses structured input ( a text file ),
I am after some input/guidance.. I have an application that uses a central configuration
On the site I am developing, I have a file input that users can
I have a import file page that has a form with a file input
I have some code that uses a multi-part form and HTML5 file object to

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.