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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:02:19+00:00 2026-05-27T09:02:19+00:00

I keep getting the above error when trying to transform XML that’s generated in

  • 0

I keep getting the above error when trying to transform XML that’s generated in code to a plain text output.

My .xsl file is:

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="text"/>
      <xsl:template match="/">
          <xsl:text>Test</xsl:text>
      </xsl:template>
</xsl:transform>

And my C# method code is:

       if( !File.Exists( xslPath ) )
            throw new Exception( "XSL File (" + xslPath + ") does not exist" );

        XslTransform docXsl = new XslTransform();
        docXsl.Load( xslPath );

        XmlDocument docXml = new XmlDocument();

        XmlElement emailNode = docXml.CreateElement("Email");
        docXml.AppendChild( emailNode );

        XmlResolver xres = null;
        XmlReader xr = docXsl.Transform( docXml, null, xres );

        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load( xr );

        return xmldoc.OuterXml;

The XML generated is very simple, just

<Email/>

If I remove the node from the XSL, then I do not get the error.

I cannot find out why this is happening. Any help would be greatly appreciated.

Thanks

  • 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-27T09:02:19+00:00Added an answer on May 27, 2026 at 9:02 am

    What is it that you want to achieve? If you use .NET 2.0 or later you shouldn’t use XslTransform at all, rather XslCompiledTransform. And if you want plain text output then it does not make any sense to try to load that transformation result into an XmlDocument as that object model is meant to contain a well-formed XML document and not some plain text. So that is the reason I think you get the error, your transformation result is plain text with a single text node and then you try to load that single text node into an XmlDocument which looks for a root element which does not exist.
    Consider to tell is which .NET version you use/target and what kind of output you want (e.g. plain text file or string with the transformation result), then we can point you to the right overload of the Transform method of XslCompiledTransform http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.transform.aspx to get that result.

    For instance if your transformation input is an XmlDocument or other object implementing IXPathNavigable you can use http://msdn.microsoft.com/en-us/library/ms163435.aspx to transform to a StringWriter to get an String result as follows:

    XslCompiledTransform proc = new XslCompiledTransform();
    proc.Load(xslPath);
    
    string result;
    
    using (StringWriter sw = new StringWriter())
    {
      proc.Transform(docXml, null, sw);
      result = sw.toString();
    }
    
    return result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
Keep getting this error after inserting a subdatasheet into a query and trying to
I am trying to grab a webpage with actionscript, but keep getting this error
I'm trying to use slime from CVS (2009-01-05) but keep getting this error: LOAD:
I keep getting the following error message when trying to UPDATE one of my
I keep getting a PermGen error on my Tomcat 6 server. I know what
I keep getting empty files generated from running $command = 'mysqldump --opt -h localhost
I keep getting a 'List does not exist' error whenever I try and use
We are getting the above error when we try and run our tests in
I'm having a problem with some PHP code I'm trying to use. I keep

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.