Translate XML String into HTML string using XSL file

Hi,

I need to be able to translate an xml string using an xsl file and return the html output to a string for display.

I used to do the following in VB 6:

Private Function GetHTMLString(ByVal strXMLString  as String) as String
 
  Dim objXML as MSXML2.DOMDocument40
  Dim objXSL as MSXML2.DOMDocument40
  Set objXML = New MSXML2.DOMDocument40
  Set objXSL = New MSXML2.DOMDocument40

  strXMLString = "<?xml version='1.0'?><report><colour>red</colour></report>"
  objXML.loadXML (strXMLString)
  objXSL.Load ("c:\temp\test.xsl")

  GetHTMLString= objXML.transformNode(objXSL)

  Set objXML = Nothing
  Set objXSL = Nothing
End Function

Can anyone tell me how this is done in VB.Net - I have seen a lot of examples where the xml is translated from a file, but I don't want to actually use a file, probably just build up the XML string from a recordset and pass it into this function...

Thanks in advance...
R
LVL 4
rallsaldoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

J_MakCommented:
0
rallsaldoAuthor Commented:
Hi,
Thanks,... I had looked at this link - however I am a bit puzzled as to how to simply use xml as a string and use the filepath of an xsl document....
This just seems to give me examples where the xml is loaded in from a file?... am I missing something? probably really obvious...

Would appreciate your help..

Thanks,
R
0
J_MakCommented:
Try something like this:

Private Function GetHTMLString(ByVal strXMLString  as String) as String
 
  Dim objXML as MSXML2.DOMDocument40
  Dim objXSL as MSXML2.DOMDocument40
  Set objXML = New MSXML2.DOMDocument40
  Set objXSL = New MSXML2.DOMDocument40

  strXMLString = "<report><colour>red</colour></report>"
  objXML.loadXML (strXMLString)
  objXSL.Load ("c:\temp\test.xsl")

  GetHTMLString= objXML.transformNode(objXSL)

  Set objXML = Nothing
  Set objXSL = Nothing
End Function

OTherwise try this:

Dim objXML as XmlDocument = new XmlDocument()
Dim objXSL as XslTransform = new XslTransform()

strXMLString = "<report><colour>red</colour></report>"
objXML.loadXML (strXMLString)
objXSL.Load ("c:\temp\test.xsl")

objXSL.Transform(doc, GetHTMLString)

Set objXML = Nothing
Set objXSL = Nothing

GetHTMLString would contain the filename of your html resutl. I have not tested it but it should give you a good start. Cheers.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rallsaldoAuthor Commented:
Hi, Thanks for this.... the second way is what I am after (the first is good but I don't want to have a reference to the MSXML2.DOMDocument40). However its the line:

objXSL.Transform(doc, GetHTMLString)

that I can't get to work... what is the doc reference?

Thanks for your help,
R
0
rallsaldoAuthor Commented:
This is what I was after but thanks for your help.


Public Function GetTransformedHTML(ByVal strXML As String, ByVal strXSLFile As String) As String
        Dim XMLDoc As New System.Xml.XmlDocument   'XPathDocument
        Dim XSLTDoc As XslTransform
        Dim swWriter As StringWriter = New StringWriter
        XMLDoc.LoadXml(strXML)
        XSLTDoc = New XslTransform
        XSLTDoc.Load(strXSLFile)
        XSLTDoc.Transform(XMLDoc, Nothing, swWriter)
        GetTransformedHTML = swWriter.ToString()
    End Function

Cheers,
R
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.