rallsaldo
asked on
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><co lour>red</ colour></r eport>"
objXML.loadXML (strXMLString)
objXSL.Load ("c:\temp\test.xsl")
GetHTMLString= objXML.transformNode(objXS L)
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
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><co
objXML.loadXML (strXMLString)
objXSL.Load ("c:\temp\test.xsl")
GetHTMLString= objXML.transformNode(objXS
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
objXSL.Transform(doc, GetHTMLString)
that I can't get to work... what is the doc reference?
Thanks for your help,
R
ASKER
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
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
http://samples.gotdotnet.com/quickstart/howto/doc/Xml/TransformXml.aspx