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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:11:31+00:00 2026-06-03T02:11:31+00:00

I have successfully been able to transform a simple xml file with data to

  • 0

I have successfully been able to transform a simple xml file with data to another xml file (excel template) using a xsl template, this is what my xsl file looks like:

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

    <xsl:template match="/">
      <xsl:processing-instruction name="mso-application">
        <xsl:text>progid="Excel.Sheet"</xsl:text>
      </xsl:processing-instruction>
    ...(stuff here)...
    </xsl:template>
  </xsl:stylesheet>

The resulting xml file is written out correctly BUT with the exception of including

<?xml version="1.0"?>

at the top of the file. How can I get it to appear at the top?

Currently my resulting xml file starts with:

<?mso-application progid="Excel.Sheet"?>
...(rest of file)...

But what I need it to do is:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
.(rest of file)...

I’m doing this transform through a windows form with the following code:

XPathDocument myXPathDoc = new XPathDocument(xmlfile);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(xslfile);
XmlTextWriter myWriter = new XmlTextWriter(xmlexcelfile, null);
myWriter.Formatting = Formatting.Indented;
myWriter.Namespaces = true;
myXslTrans.Transform(myXPathDoc, null, myWriter);
myWriter.Close();

I’ve tried playing around with the xsl:output standalone="yes/no", as well as omit-xml-declaration="no". I’ve also tried (in the C#) code adding myWriter.WriteStartDocument(); before transforming but that was not allowed. I have tried searching online for this as well and keep coming back to the standalone="yes" but that isn’t working. Is there something I am missing here? Oh and in case you are wondering why I need to have the

<?xml version="1.0"?>

at the top of the resulting file, it’s because when opening the xml file with excel, excel doesn’t recognize it correctly but if it is included then excel opens it correctly…

  • 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-03T02:11:33+00:00Added an answer on June 3, 2026 at 2:11 am

    You can do this

    <xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
    

    or something similar to this using XmlWriterSettings

    Edit: Added more code. Previous was missing some parts

            XmlWriterSettings writerSettings = null;
            XsltArgumentList transformationArguments = null;
            XslCompiledTransform transformer = null;
            MemoryStream memoryStream = null;
            XPathDocument xPathDocument = null;
            StringBuilder sb = null;
            XmlWriter writer = null;
            XmlDocument resultXml = null;
            try
            {
                writerSettings = new XmlWriterSettings();
                writerSettings.OmitXmlDeclaration = false; // This does it
                writerSettings.Indent = true;
    
                transformationArguments = new XsltArgumentList();
                transformer = new XslCompiledTransform();
                memoryStream = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml.OuterXml));
                xPathDocument = new XPathDocument(new StreamReader(memoryStream));
                sb = new StringBuilder();
                // give the settings to the writer here
                writer = XmlWriter.Create(sb, writerSettings);
                // this is not mandatory, obviously, just passing parameters to my xslt file
                foreach (KeyValuePair<string, object> parameter in parameters)
                {
                    transformationArguments.AddParam(parameter.Key, string.Empty, parameter.Value);
                }
    
                using (Stream strm = Assembly.GetExecutingAssembly().GetManifestResourceStream("Lib.XSLTFile1.xslt"))
                using (XmlReader reader = XmlReader.Create(strm))
                {
                    transformer.Load(reader);
                    transformer.Transform(xPathDocument, transformationArguments, writer);
                }
                resultXml = new XmlDocument();
                resultXml.LoadXml(sb.ToString());
                // for testing only
                File.AppendAllText(@"Your path goes here\result.xml", resultXml.OuterXml);
            }
            catch (Exception)
            {
                throw;
            }
    

    This is how I do it, but this code is specifically written to create an instance of a XmlDocument. I’m sure you can adapt to your needs.

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

Sidebar

Related Questions

I have been able to successfully get an access token from Vimeo using the
I've been able to have JPA/Hibernate to replicate the ON DELETE CASCADE functionality successfully
All these years i have been successfully using EnumServicesStatus in combination with OpenScManager (with
I have a Linq-To-Sql based repository class which I have been successfully using. I
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
I have been using fullcalendar plugin successfully for a few months and suddenly ran
I am building a Winforms C# 2.0 application. I have successfully been able to
I've successfully been able to make elements (like div's, panel's, whatever) draggable by using
I am using Martin Orth's ColdFusion API for Google Adwords. I have been able
I have been successfully debugging several projects using Eclipse 3.4.1 with Zend Debugger and

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.