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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:06:33+00:00 2026-05-11T05:06:33+00:00

In native programming the IXMLDOMDocument2 object had a tranformNode() method: public BSTR transformNode(IXMLDOMNode stylesheet);

  • 0

In native programming the IXMLDOMDocument2 object had a tranformNode() method:

public BSTR transformNode(IXMLDOMNode stylesheet); 

So in the end I could transform an XML document using:

public string TransformDocument(IXMLDOMDocument2 doc, IXMLDOMDocument2 stylesheet) {    return doc.TransformNode(stylesheet); } 

I’m trying to find the managed equivalent. I’ve already discovered XmlDocument object:

public string TransformDocument(XmlDocument doc, XmlDocument stylesheet) {    //return doc.TransformNode(stylesheet); //TransformNode not supported } 

So what is the managed way to transform xml?

I’ve stumbled across the deprecated XslTransform object, but none of the 18 overloads takes an xml document, or an xml stylesheet.

The replacement Microsoft indicates is the mouthful: System.Xml.Xsl.XslCompiledTransform. But like it’s deprecated cousin, none of XslCompiledTransform’s 14 overloads takes xml in an input parameter.

So what’s the accepted method to transform xml in C# .NET 2.0?

Put it another way: complete the following helper method:

public string TransformDocument(XmlDocument doc, XmlDocument stylesheet) {    //todo: figure out how to transform xml in C# } 

Answer

Waqas had the answer. Here is another, very similar, solution:

/// <summary> /// This method simulates the XMLDOMDocument.TransformNode method /// </summary> /// <param name='doc'>XML document to be transformed</param> /// <param name='stylesheet'>The stylesheet to transform with</param> /// <returns></returns> public static string Transform(XmlDocument doc, XmlDocument stylesheet) {     XslCompiledTransform transform = new XslCompiledTransform();     transform.Load(stylesheet); // compiled stylesheet      System.IO.StringWriter writer = new System.IO.StringWriter();     transform.Transform(doc, XmlWriter.Create(writer));      return writer.ToString();    } 

Note: If you’re a performance weenie, you might want to create an overload to pass the pre-compiled transform, if you’re going to transforming more than once.

public static string Transform(XmlDocument doc, XslCompiledTransform stylesheet) {    ... } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:06:34+00:00Added an answer on May 11, 2026 at 5:06 am

    The functions take IXPathNavigable objects as input (and XmlDoucment/XmlNode classes implement IXPathNavigable).

    Here’s how it would work:

    public string TransformDocument(XmlDocument doc, XmlDocument stylesheet) {    XslCompiledTransform transform = new XslCompiledTransform();    transform.Load(stylesheet); // compiled stylesheet    System.IO.StringWriter writer = new System.IO.StringWriter();    transform.Transform(doc, null, writer);    return writer.ToString(); } 

    Optimizations and improvements:

    • Cache the compiled stylesheet if you use it more than once.
    • Load the XSL directly into the XslCompiledTransform instead of building an XmlDocument first.
    • Use XmlNode instead of XmlDocument to make the function more generic.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 83k
  • Answers 83k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's not that MySQL and other DBs sort things on… May 11, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer consider: A ::= A B the equivalent code is boolean… May 11, 2026 at 4:53 pm
  • Editorial Team
    Editorial Team added an answer I'm not an expert with StringTemplate, but I found a… May 11, 2026 at 4:53 pm

Related Questions

I'm writing an editor for large archive files (see below) of 4GB+, in native&managed
My main experience is with C && C++, so I'd prefer to remain with
I've noticed that there are awvully few programming tutorials in my native language (Latvian).
So, one commonly heard comment when talking about performance is that you write your

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.