Transform XML string using XSLT file

  • Thread starter Isambella via DotNetMonster.com
  • Start date
I

Isambella via DotNetMonster.com

Hi,

I have in a string some XML and I want that xml to be transformed using XSLT
file (I found the way how to transform a xml file using XSLT but I didn’t
find a way how to transform using string)

Help me pls

thx in advance
Isambella
 
G

Guest

One method is to use XML web control
<asp:Xml id="xmlCtrl" runat="server" />

Load your stirng using LoadXml method of XmlDocument class and assign XML
and XSL objects to XML web control

XmlDocument oXML = new XmlDocument();
oXML.LoadXml(yourXmlString);

XslTransform oXSL = new XslTransform();
oXSL.Load(Server.MapPath("yourXslFileName.xsl"));

xmlCtrl.Document = oXML;
xmlCtrl.Transform = oXSL;


Sreejith
 
B

Bruce Barker

use the StringReader class to create a stream that can be passed xlst.

-- bruce (sqlwork.com)
 
I

Isambella via DotNetMonster.com

Hi again

thx

I solve the problem, the answer is the following

------------------------------------------------------------------------------
-------------------------------------
str = "has the XML code"

Dim oTrasform As New XslTransform
Dim Resp As System.IO.Stream

Dim myDoc As New System.Xml.XmlDocument
Dim args As New XsltArgumentList

myDoc.LoadXml(str)

Dim txt As New System.IO.MemoryStream
Dim output As New System.Xml.XmlTextWriter(txt, System.Text.Encoding.UTF8)


oTrasform.Load(Get_Xslt_Formatter_Path())

oTrasform.Transform(myDoc, args, output, Nothing)

output.Flush()
txt.Position = 0

Dim sr As New StreamReader(txt)

textbox1.text = sr.ReadToEnd()
------------------------------------------------------------------------------
-------------------------------------


Bruce said:
use the StringReader class to create a stream that can be passed xlst.

-- bruce (sqlwork.com)
[quoted text clipped - 7 lines]
thx in advance
Isambella
 
I

Isambella via DotNetMonster.com

Hi again

thx

I solve the problem, the answer is the following

------------------------------------------------------------------------------
-------------------------------------
str = "has the XML code"

Dim oTrasform As New XslTransform
Dim Resp As System.IO.Stream

Dim myDoc As New System.Xml.XmlDocument
Dim args As New XsltArgumentList

myDoc.LoadXml(str)

Dim txt As New System.IO.MemoryStream
Dim output As New System.Xml.XmlTextWriter(txt, System.Text.Encoding.UTF8)


oTrasform.Load(Get_Xslt_Formatter_Path())

oTrasform.Transform(myDoc, args, output, Nothing)

output.Flush()
txt.Position = 0

Dim sr As New StreamReader(txt)

textbox1.text = sr.ReadToEnd()
------------------------------------------------------------------------------
-------------------------------------


Bruce said:
use the StringReader class to create a stream that can be passed xlst.

-- bruce (sqlwork.com)
[quoted text clipped - 7 lines]
thx in advance
Isambella
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top