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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:30:25+00:00 2026-05-16T00:30:25+00:00

I need to transform an XML file to another XML file, where the source

  • 0

I need to transform an XML file to another XML file, where the source file has a dynamic namespace set to xmlns="whatever". My XSLT runs fine without the namespace being in the file, but I get no output with the namespace. How can I cause the schema of the source file to be applied to the destination file?

All help is appreciated and thanks in advance!

EDIT:

I’m trying to copy the namespace uri over to the resulting file:

<xsl:param name="schema">
    <xsl:value-of select="namespace-uri()" />
</xsl:param>

<xsl:element name="root" namespace="$schema">

I have verified that schema is holding the correct value, but the problem is that the program appears to take this too literally:

<root xmlns="$schema">

Is this the right way to go about this?

EDIT x2:

I’ve implemented Alejandro’s suggestion of:

<xsl:element name="root" namespace="{$schema}"/> 

And that works for the most part, except for the fact that I have to put the namespace on every element or else I get the following structure in the result:

<root xmlns="NAMESPACE">
    <foo xmlns="">

etc.

Is there a way to blanket all of the elements with this namespace, other than putting namespace={$schema} on every single line? Bounty and accept for the best answer!

EDIT x3:
Better example:

If I do:

<xsl:element name="root" namespace="{namespace-uri()}>
  <xsl:element name="foo">
    <xsl:element name="bar">
    <!--etc-->
    </xsl:element>
  </xsl:element>
</xsl:element>

I get:

<root xmlns="NAMESPACE">
  <foo xmlns="">
    <bar>
    <!--etc-->
    </bar>
  </foo>
<root>

I would like to have them all under namespace NAMESPACE, so I did:

<xsl:element name="root" namespace="{namespace-uri()}>
  <xsl:element name="foo" namespace="{namespace-uri()}>
    <xsl:element name="bar" namespace="{namespace-uri()}>
    <!--etc-->
    </xsl:element>
  </xsl:element>
</xsl:element>

However this is ugly and tedious to type. Is there an easier way to blanket the namespace over all elements? (hopefully this clarifies what I need)

  • 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-16T00:30:26+00:00Added an answer on May 16, 2026 at 12:30 am

    Suppose you have this XML input:

    <root xmlns="survivors"> 
      <louis/> 
      <francis/> 
    </root> 
    

    Meaning that every element is under default namespace wich its URI is “survivors”.

    As Welbog wrote you can select francis element with:

    /*/*[local-name()='francis']
    

    or

    /*[local-name()='root']/*[local-name()='francis']
    

    But, that also select francis element from these XML inputs:

    <root xmlns="survivors" xmlns:n="no-survivors"> 
      <louis/> 
      <n:francis/> 
    </root> 
    

    or

    <root xmlns="survivors"> 
      <louis/> 
      <francis xmlns="no-survivors"/> 
    </root> 
    

    You could also strengthen the predicate with some namespace URI. But, wich one? An option could be the default namespace for root element like:

    /*/*[local-name()='francis'][namespace-uri()=namespace-uri(/*)]
    

    Surely this make XPath expression very verbose.

    In XSLT 2.0 you could use xsl:xpath-default-namespace attribute like:

    <xsl:value-of select="/root/francis" xpath-default-namespace="survivors"/> 
    

    But that’s not good for your case because you don’t know the URI in advance.

    EDIT: xsl:element ‘s attributes are AVT (Attribute Value Template) so you need this:

    <xsl:element name="root" namespace="{$schema}"/> 
    

    Also, I recomend you to declare the param as a string data type (not RTF like now), something like:

    <xsl:param name="schema" select="namespace-uri()"/> 
    

    EDIT 2: Maybe I was not clear. You don’t need xsl:element/@namespace in every case. Following your statement that every element is in only one default namespace, this stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="@*|node()">
            <xsl:copy>
                    <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="*[local-name()='bar']">
            <xsl:element name="newbar" namespace="{namespace-uri()}">
                    <xsl:apply-templates select="@*|node()"/>
            </xsl:element>
        </xsl:template>
    </xsl:stylesheet>
    

    With this input:

    <root xmlns="whatever">
        <foo/>
        <bar/>
    </root>
    

    Output:

    <root xmlns="whatever">
        <foo></foo>
        <newbar></newbar>
    </root>
    

    Edit 2: I was showing you that when you are copying an element you are also copying the namespace needed for expand the QName. So, if want to transform this:

    <root xmlns="whatever">
        <foo/>
        <bar/>
    </root>
    

    Into this:

    <root xmlns="whatever">
        <foo>
            <bar/>
        </foo>
    </root> 
    

    You can use this stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="*">
            <xsl:copy>
                <xsl:apply-templates select="*[1]|following-sibling::*[1]"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 475k
  • Answers 475k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No. I did a small test, inserting current_timestamp from 5… May 16, 2026 at 4:43 am
  • Editorial Team
    Editorial Team added an answer You want to remove a badge from the current tab,… May 16, 2026 at 4:43 am
  • Editorial Team
    Editorial Team added an answer First you need to be explicit about the replacement conditions,… May 16, 2026 at 4:43 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.