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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:49:02+00:00 2026-05-25T16:49:02+00:00

I have a simple XML file with simple XSLT transform and XslCompiledTransform does a

  • 0

I have a simple XML file with simple XSLT transform and XslCompiledTransform does a good job when I don’t have any xmlns in my XML file, but when I do the resulting XML file is empty – why?

Here is my code:

    public static void XmlToXmlWithXsl(string xmlFilePath, string xmlOutputFilePath, string xslFilePath)
    {
        // Load the style sheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load(xslFilePath);

        // Create the writer.
        XmlWriterSettings settings = xslt.OutputSettings;
        XmlWriter writer = XmlWriter.Create(xmlOutputFilePath, settings);

        // Execute the transformation.
        xslt.Transform(xmlFilePath, writer);
        writer.Close();
    }

Here is my XML (version with xmlns):

<?xml version="1.0" encoding="utf-8"?>
<messages xmlns="blah">
    <message>
        <id>blah</id>
        <text>Polski</text>
        <text lang="en">English</text>
        <notes />
    </message>

    <message>
        <id>blah2</id>
        <text lang="pl">Polski</text>
        <text lang="en">English</text>
        <notes />
    </message>
</messages>

Here is my XSL (little smaller then it was):

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

    <xsl:variable name="empty_string"></xsl:variable>

    <!-- root -->
    <xsl:template match="/">
        <xsl:element name="messages">
            <xsl:apply-templates select="//message" />
        </xsl:element>
    </xsl:template>

    <!-- AS-IS with xml content -->
    <xsl:template match="message">
        <xsl:element name="{name(.)}"><xsl:apply-templates /></xsl:element>
    </xsl:template>

    <!-- AS-IS with text content -->
    <xsl:template match="id|notes|text">
        <xsl:element name="{name(.)}"><xsl:value-of select="." /></xsl:element>
    </xsl:template>

</xsl:stylesheet>

The output is:

<?xml version="1.0" encoding="utf-8"?>
<messages xmlns="blablabla" />

The output should be:

<?xml version="1.0" encoding="utf-8"?>
<messages xmlns="blablabla">
  <message>
        <id>blah</id>
        <text>Polski</text>
        <text>English</text>
        <notes></notes>
    </message>
  <message>
        <id>blah2</id>
        <text>Polski</text>
        <text>English</text>
        <notes></notes>
    </message>
</messages>
  • 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-25T16:49:03+00:00Added an answer on May 25, 2026 at 4:49 pm

    This is the XSLT/XPath 1.0 FAQ: to select or match elements in a certain namespace, even the default namespace, with XSLT/XPath 1.0 you need to bind a prefix to the namespace URI and use that prefix in path expressions or match patterns to qualify element names:

    <xsl:stylesheet version="1.0"
        xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
        xmlns:df="blablabla"
    >
        <xsl:output method="xml" indent="yes" />
    <xsl:variable name="empty_string"></xsl:variable>
    
    <!-- root -->
    <xsl:template match="/">
        <xsl:element name="messages">
            <xsl:apply-templates select="//df:message" />
        </xsl:element>
    </xsl:template>
    
    <!-- AS-IS with xml content -->
    <xsl:template match="df:message">
        <xsl:element name="{name(.)}"><xsl:apply-templates /></xsl:element>
    </xsl:template>
    
    <!-- AS-IS with text content -->
    <xsl:template match="df:id|df:notes|df:text">
        <xsl:element name="{name(.)}"><xsl:value-of select="." /></xsl:element>
    </xsl:template>
    

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

Sidebar

Related Questions

I have a really simple XML file that I'm trying to read, but I
i have a simple xml file in a wcf service that i am trying
I have a simple xml file and I want to remove everything before the
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
I have a simple XML file like so: <?xml version=1.0 encoding=UTF-8?> <foo attr=blah &#176;
Simple question. I have an XML file with a few dozens of comment blocks.
i have simple XML file: <MyRoot> <Value key=TARGET>foo</Value> <Value key=MODEL>bar</Value> <Value key=MANUFACTURER>bla</Value> </MyRoot> and
I have a simple XML file as shown below. <?xml version=1.0 encoding=UTF-8?> <myConfig> <datasets>
I have a simple xml file. I know which fields it will have ahead
I am using Visual Studio 2010 and I have a simple XML file which

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.