Question

Frequently I make the transformation of XML files by applying an XSLT stylesheet. Now to simplify this procedure, I created this Form with VBasic 2008 Express Edition: enter image description here

You Can see that I insert in a label the path of XML (Label2) and in another label (Label4) the path of XSLT file.

There is a tool that allows to make this transformation at Button1.Click?

With Visual Basic 6 I remember that I can insert a Macro. I created this macro:

Sub Macro1()

ChangeFileOpenDirectory "C:\Users\f.irrera\Desktop\File_DAF\"
Documents.Open FileName:="Fascicolo 4 del 2013.xml", ConfirmConversions:= _
    False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
    PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
    WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
ActiveDocument.Close
Documents.Open FileName:= _
    "C:\Users\f.irrera\Desktop\File_DAF\Fascicolo 4 del 2013.xml", _
    XMLTransform:="C:\Users\f.irrera\Desktop\File_DAF\Tirone.xslt"

End Sub
Was it helpful?

Solution

' Create the XslTransform object and load the style sheet. File XSLT
Dim xslt As New XslCompiledTransform()
xslt.Load(Label4.Text)

' Load the file to transform. File XML
Dim doc As New Xml.XPath.XPathDocument(Label2.Text)

' Create the writer.
Dim writer As XmlWriter = XmlWriter.Create("Fascicolo.doc", xslt.OutputSettings)

' Transform the file and send the output to the console.
xslt.Transform(doc, writer)

writer.Close()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top