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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:49:12+00:00 2026-05-17T02:49:12+00:00

After scouring the net for answers, coming up with almost solutions… I decided to

  • 0

After scouring the net for answers, coming up with “almost” solutions… I decided to reduce the problem to a very simple case.

Consider the following XML snippet:

<me:root xmlns:me="http://stackoverflow.com/xml"
  xmlns="http://www.w3.org/1999/xhtml">
    <me:element>
        <p>Some HTML code here.</p>
    </me:element>
</me:root>

Note that the p element is of XHTML’s namespace, which is the default one for this doc.

Now consider the following simple stylesheet. I want to create an XHTML document, with the contents of me:element as the body.

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:me="http://stackoverflow.com/xml"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="me">
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>My Title</title>
            </head>
            <body>
                <xsl:copy-of select="me:root/me:element/node()"/>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Note that I included exclude-result-prefixes… But see what I get:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>My Title</title>
    </head>
    <body>
        <p xmlns:me="http://stackoverflow.com/xml">Some HTML code here.</p>
    </body>
</html>

And what’s driving me insane here is why, oh why does xmlns:me appears inside the p element?

No matter what I tried, I couldn’t get stuff to work. I have a strange feeling that the problem is with my xsl:copy-of statement.

  • 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-17T02:49:12+00:00Added an answer on May 17, 2026 at 2:49 am

    I have a strange feeling that the
    problem is with my xsl:copy-of
    statement.

    This is exactly the reason.

    The source XML document contains this fragment:

    <me:element> 
        <p>Some HTML code here.</p> 
    </me:element> 
    

    In the XPath data model, namespace nodes are propagated from a root of a subtree to all of its descendents. Therefore, the <p> element has the following namespaces:

    1. "http://www.w3.org/1999/xhtml"

    2. "http://stackoverflow.com/xml"

    3. "http://www.w3.org/XML/1998/namespace"

    4. http://www.w3.org/2000/xmlns/

    The last two are reserved namespaces (for the prefixes xml: and xmlns) and are available to any named node.

    The reported problem is due to the fact that by definition the <xsl:copy-of> instruction copies all nodes and their complete subtrees with all namespaces belonging to each of the nodes.

    Remember: the prefixes specified as the value of the exclude-result-prefixes attribute are excluded only from literal-result elements!

    Solution:

    <xsl:stylesheet version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:me="http://stackoverflow.com/xml"
      xmlns="http://www.w3.org/1999/xhtml"
      exclude-result-prefixes="me">
    
      <xsl:output method="xml" omit-xml-declaration="yes"
      indent="yes"/>
      <xsl:strip-space elements="*"/>
    
        <xsl:template match="/">
         <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
            <title>My Title</title>
          </head>
          <body>
            <xsl:apply-templates select="me:root/me:element/*"/>
          </body>
         </html>
        </xsl:template>
    
        <xsl:template match="*">
          <xsl:element name="{name()}">
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates/>
          </xsl:element>
        </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <me:root xmlns:me="http://stackoverflow.com/xml"
      xmlns="http://www.w3.org/1999/xhtml">
        <me:element>
            <p>Some HTML code here.</p>
        </me:element>
    </me:root>
    

    the wanted, correct result is produced:

    <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
          <title>My Title</title>
       </head>
       <body>
          <p>Some HTML code here.</p>
       </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure that this is very straight-forward, however, after scouring the net I can't
I've been stuck on this likely very simple problem, but haven't gotten anywhere with
Python metacharacter negation. After scouring the net and writing a few different syntaxes I'm
After thinking for long, I have decided to build my data app for the
I have an excel vba problem that I am trying to solve and after
I've been scouring the net and Apple help for some sort of guidance on
I am sure that this must be a pretty common question but after scouring
I've been trying haplessly for hours so I thought I should ask (after scouring
I am building a simple Firefox extension using the Add-on SDK 1.0. Scouring the
So after scouring the Internet I pieced together the following code to upload a

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.