Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2003, 12:12 PM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dimondwoof
Default 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???????
 
Old June 26th, 2003, 01:22 PM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have no experience with .NET XML but I hope that this excerpt from VB6 will help you. It shows how to transform source XML document to output XML document according to given XSLT transformation, using MSXML 4.0 object model. I suppose that .NET XML has similar solution.

Dim XmlXSLTFile As String
Dim XmlSrcFile As String
Dim XmlOutFile As String

' file names
XmlXSLTFile = "f:\winnt\itConfig\itRegistryOutput.xsl"
XmlSrcFile = "f:\winnt\itConfig\itRegistry.xml"
XmlOutFile = "f:\winnt\itConfig\itRegistryOut.xml"

' load XSLT (in memory)
Dim XmlXSLT As MSXML2.DOMDocument40
Set XmlXSLT = New MSXML2.DOMDocument40
XmlXSLT.Load (XmlXSLTFile)

' load source XML document file (in memory)
Dim XmlDoc As MSXML2.DOMDocument40
Set XmlDoc = New MSXML2.DOMDocument40
XmlDoc.Load (XmlSrcFile)

' create new empty output (in memory) document
Dim XmlOut As MSXML2.DOMDocument40
Set XmlOut = New MSXML2.DOMDocument40

' transform source document to output document according to
' given XSLT
XmlDoc.transformNodeToObject XmlXSLT, XmlOut

' save output XML document to file
XmlOut.save (XmlOutFile)

Best regards, Miran.





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt document function.. maddukuri XSLT 8 May 16th, 2008 06:31 AM
xslt document() function problem with servlet meps XSLT 3 December 20th, 2005 10:34 AM
Problem applying simple XSLT to XML to create CSV gregclark XSLT 2 August 25th, 2005 07:30 AM
xslt 2.0 document function jkmyoung XSLT 2 November 18th, 2004 03:21 PM
Applying an XSLT to an XML document (II) Thodoris XML 1 April 28th, 2004 09:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.