使用Visual Basic 2008将XSLT应用到XML中 - XMLTransform-

时间:2014-05-13 15:06:12

标签: visual-studio-2010 visual-studio visual-studio-2012 visual-studio-2008

我经常通过应用XSLT样式表来转换XML文件。 现在为了简化此过程,我使用VBasic 2008 Express Edition创建了此表单: enter image description here

您可以看到我在标签中插入了XML(Label2)的路径,并在另一个标签(Label4)中插入了XSLT文件的路径。

有一个工具可以在Button1.Click?

进行转换

使用Visual Basic 6我记得我可以插入一个宏。 我创建了这个宏:

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

1 个答案:

答案 0 :(得分:0)

' 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()