We have an XML-string and an XSLT-string. We want to transform the XML and save the result in a string. The code is in VB.NET
To perform the transform we need to put both the XML and the XSLT into a XML-document. Then we can save the result of the transformation in a stream, in this case a stringwriter.
Code:
Private Function TranslatedXML(ByVal XML As String, ByVal XSLT As String) As String
Dim xmld As XmlDocument
Dim xsltd As XmlDocument
Dim xct As XslCompiledTransform
Dim sw As StringWriter
'Create an XML-document with the given XSLT
xsltd = New XmlDocument
xsltd.LoadXml(XSLT)
'Create the XslCompiledTransform using the create XML-document
xct = New XslCompiledTransform
xct.Load(xsltd)
'Create an XML-document with the XML to transform
xsd = New XmlDocument
xsd.LoadXml(XML)
'Create an output-stream for the transform
sw = New StringWriter()
'Perform the actual transform
xs.Transform(xsd, Nothing, sw)
Return sw.ToString
End Function