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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:36:43+00:00 2026-05-30T20:36:43+00:00

Here is what I’m trying to do: I’ve got an XmlDocument, which is already

  • 0

Here is what I’m trying to do: I’ve got an XmlDocument, which is already loaded into memory. I want to apply an xsl transformation to a single node of that document.

here’s the code:

var xDoc=GetXmlDocument();
var myNode=xDoc.SelectSingleNode("//node");
var xslTransformer=new XslCompiledTransform(); 
xslTransformer.Load(new XmlTextReader(new StringReader(myXslText)));

Now I need to apply xslTransformer on myNode. Can anyone show me a code example, which does that? What I’ve seen so far only works with input and output files.

  • 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-30T20:36:44+00:00Added an answer on May 30, 2026 at 8:36 pm

    Here is an example how to do this, taken from the MSDN documentation:

    // Load an XPathDocument.
    XPathDocument doc = new XPathDocument("books.xml");
    
    // Locate the node fragment.
    XPathNavigator nav = doc.CreateNavigator();
    XPathNavigator myBook = nav.SelectSingleNode("descendant::book[@ISBN = '0-201-63361-2']");
    
    // Create a new object with just the node fragment.
    XmlReader reader = myBook.ReadSubtree();
    reader.MoveToContent();
    
    // Load the style sheet.
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load("single.xsl");
    
    // Transform the node fragment.
    xslt.Transform(reader, XmlWriter.Create(Console.Out, xslt.OutputSettings));
    

    For more information see: http://technet.microsoft.com/en-us/library/wkx4fcc4.aspx

    Do note:

    When you transform data contained in an XmlDocument or XPathDocument object the XSLT transformations apply to a document as a whole. In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. To transform a node fragment, you must create a separate object containing just the node fragment, and pass that object to the Transform method.

    This is why applying the transformation on a node of a document may cause unexpected and unwanted results — for example the transformation can access other nodes, that aren’t in the provided node’s subtree — such as siblings or ancestors.

    This is why I strongly recommend not to simply call Transform() on any node (other than a document-node).

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

Sidebar

Related Questions

Here's a problem I ran into recently. I have attributes strings of the form
Here is my code, which takes two version identifiers in the form 1, 5,
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here's my situation. I have a DotNetNuke application. I want to link to an
here is what I want to do: Add a CALayer as a sublayer to
Here is my code...I have two dimensional matrices A,B. I want to develop the
here i want to understand the architecture of bluez (Bluetooth Stack Protocol). I understood
Here is my code (Say we have a single button on the page that

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.