472,779 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Simple XSL Transformations using XmlDocument

Hi,
I found the XSL Transformation through .NET too complex. The most simplest
overload of System.Xml.Xsl.XslTransform is Transform(inputfile, outputfile),
but this saves the result into file. I need to supply the XmlDocument object
(with the source tree loaded) and receive the output in string.

Traditionally I do this thing in very simple way which is as below:

dom.load "xmldoc.xml"
sdom.load "xsldoc.xsl"
str = dom.transformNode(sdom)

Could someone give the .NET equivalent for above code?
Thanks in advance,
Fahad
Nov 12 '05 #1
3 1389


Fahad Ashfaque wrote:

I need to supply the XmlDocument object
(with the source tree loaded) and receive the output in string.


XslTransform xsltProcessor = new XslTransform();
xsltProcessor.Load(new XPathDocument(xsltStylesheetURI));

StringWriter stringWriter = new StringWriter();

xsltProcessor.Transform(xmlDocument, null, stringWriter);
// use stringWriter.ToString() to get the result

Note that an XmlDocument is not necessary as the input and should be
replaced by an XPathDocument if you only want to read the document for
the tranformation as XPathDocument is optimized for XPath and XSLT.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thanks a lot Martin.

It really did help.

"Martin Honnen" wrote:


Fahad Ashfaque wrote:

I need to supply the XmlDocument object
(with the source tree loaded) and receive the output in string.


XslTransform xsltProcessor = new XslTransform();
xsltProcessor.Load(new XPathDocument(xsltStylesheetURI));

StringWriter stringWriter = new StringWriter();

xsltProcessor.Transform(xmlDocument, null, stringWriter);
// use stringWriter.ToString() to get the result

Note that an XmlDocument is not necessary as the input and should be
replaced by an XPathDocument if you only want to read the document for
the tranformation as XPathDocument is optimized for XPath and XSLT.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #3
I have an old code that simply loads xml string (xml result from the SQL
stored procedure) from database and transforms it into html string using xsl.
I'm trying to convert it into .net.
I tired different ways based on examples, but it doesn't work and have no
more time to get it by trial-and-error kind of way.
Thanks in advance for any help.

"Martin Honnen" wrote:


Fahad Ashfaque wrote:

I need to supply the XmlDocument object
(with the source tree loaded) and receive the output in string.


XslTransform xsltProcessor = new XslTransform();
xsltProcessor.Load(new XPathDocument(xsltStylesheetURI));

StringWriter stringWriter = new StringWriter();

xsltProcessor.Transform(xmlDocument, null, stringWriter);
// use stringWriter.ToString() to get the result

Note that an XmlDocument is not necessary as the input and should be
replaced by an XPathDocument if you only want to read the document for
the tranformation as XPathDocument is optimized for XPath and XSLT.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike | last post by:
I am trying to code vb.net to perform XML transformations by applying a style sheet to a XML doc. All of my XML and XSLT documents will be in either XML DOM Objects or string variables. I am not...
1
by: Larry | last post by:
I am a C++/Java programmer trying to get going with some simpe xml transformations at work here. I bought the O'Reilly book Learning xlst for kicks. Someone at work sent me this xml shown below,...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
1
by: Adam Smith | last post by:
When you do this: public void someMethod(Xmldocument xml) { XmlDocument localxml = new XmlDocument(); localxml.LoadXml(xml.OuterXml); } Are you getting all the data in localxml? I want to...
6
by: Christopher | last post by:
I am currently in the process of evaluating the performance hits of moving to the .NET platform for our application. I created a sample project that loads the transforms the same XML and XSLT in...
0
by: GSK | last post by:
I notice that when working with a medium sized XML file, (a few hundred K), that contains maybe a couple of hundred nodes, that it takes quite a while to transform the document using an XSL...
4
by: Brian Henry | last post by:
I have an XML file formated as this <?xml version="1.0" encoding="utf-8" ?> <settings> <databaseServer>Dell5100</databaseServer> <defaultDatabase>bene</defaultDatabase> </settings> ...
2
by: dondraper | last post by:
I have an application that uses a popular but simple set of JavaScript routines that implement an AJAX call used to populate a drop-down. It works for thousands of user but I have one customer...
2
by: James Fifth | last post by:
Hello and God Bless, I am stumped trying to get a simple xml database replacing certain data with other data programmatically. This is what my xml looks like. ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.