Applying an XSLT to an XML document
I have a function as follows:
Private Function TransformDocument(ByVal doc As XmlDocument, ByVal strFile As String) As XmlDocument
Try
Dim NewXMLDoc As New XmlDocument
Dim myXPathDocument As XPathDocument = New XPathDocument(strFile)
Dim myXslTransform As XslTransform = New XslTransform
myXslTransform.Load("D:\Visual Studio Projects\JBRS\JBRSConvert.xslt")
Dim reader As XmlReader = myXslTransform.Transform(myXPathDocument, Nothing)
NewXMLDoc.Load(reader)
TransformDocument = NewXMLDoc
Catch ex As Exception
MessageBox.Show("TransformDocument" & vbCr & ex.Message & vbCr & ex.GetType.ToString)
End Try
End Function
I've also tried:
Private Function TransformDocument(ByVal doc As XmlDocument, ByVal strFile As String) As XmlDocument
Try
Dim xslt As New XslTransform
Dim NewXMLDoc As New XmlDocument
xslt.Load("D:\Visual Studio Projects\JBRS\JBRSConvert.xslt")
Dim reader As XmlReader
reader = xslt.Transform(doc, Nothing)
NewXMLDoc.Load(reader)
TransformDocument = NewXMLDoc
Catch ex As Exception
MessageBox.Show("TransformDocument" & vbCr & ex.Message & vbCr & ex.GetType.ToString)
End Try
End Function
I run the code without errors, but it doesn't do anything! I get the same XML document back as the one I give it. Can anyone out there tell me how to apply an XSL template to an XML document? I can't believe how hard this is! You would think it would be one of the simplest things in the .NET world, but I can't find ANYONE who can give me code that works! Even when I write the XML out to a file (which I HATE to do, I've already got it in memory, why should I have to write it out to a file and then re-read it???)
Isn't there ANYONE out there who has applied an XSLT to an XML document in memory???????
|