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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:02:13+00:00 2026-06-02T06:02:13+00:00

I encountered a peculiar difference in xslt behavior when the root element has a

  • 0

I encountered a peculiar difference in xslt behavior when the root element has a default namespace attribute as opposed to when it does not.
I am wondering why this difference occurs.

The XML input is

<root>
    <content>xxx</content>
</root>

When the following transformation is applied

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <root>
            <xsl:apply-templates/>
        </root>
    </xsl:template>

    <xsl:template match="content">
        <w>x</w>
    </xsl:template>

</xsl:stylesheet>

the result is the expected

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <w>x</w>
</root>

But when the same transformation is applied to

<root xmlns="http://test.com">
    <content>xxx</content>
</root>

the result is different and based on the application of just default templates (which effectively output the text node value ‘xxx’):

<?xml version="1.0" encoding="UTF-8"?>
<root>xxx</root>

Addition

When this is the expected behavior in this case, then what match attribute value is needed to match the content element in the second case?

  • 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-02T06:02:14+00:00Added an answer on June 2, 2026 at 6:02 am

    so what exactly is your question? If you’re simply looking for an explanation, following is a brief one. What you’re observing is the proper behavior according to the specification. When you put a namespace on something, the parser essentially treats it as a different element entirely (than an element of the same name but no namespace). Therefore, in the second situation, when you say <xsl:template match="content">, it doesn’t match the <content> element in the XML file because it falls under the http://test.com namespace (by way of the namespace declaration on its parent). Therefore, the default templates take over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I encountered some peculiar difference in behavior of XSLT processors. I wonder what is
I encountered some curious behavior today and was wondering if it is expected or
I encountered a very strange behavior in Python, a behavior that is not consistent.
I encountered a new error/bug I have not seen before. What does this refer
I encountered a very strange behavior when i m trying to insert a NSMutableDictonary
I'm attempting to P/Invoke a C library from F#, and have encountered a peculiar
Encountered a problem on posting comment back to a comment box. post not showing
I encountered an interesting problem today which I thought was not possible in Java.
I encountered a, at least to my expectations, strange behavior in the binary serialization
I have a C++/CLI .net application and I encountered a peculiar exception the other

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.