Question

I created this form to convert XML file with a XSLT file and create a DOC file. Generally I used open my XML file with Word and after I select a XSLT file and after create a doc File with the Style.

The code at the end page is in C# can You give me help to translate it in Visual Basic 2008?

enter image description here

"The XslTransform class ignored xsl:output settings when the transform output was sent to an XmlWriter object. The XslCompiledTransform class has an OutputSettings property that returns an XmlWriterSettings object containing the output information derived from the xsl:output element of the style sheet. The XmlWriterSettings object is used to create an XmlWriter object with the correct settings that can be passed to the Transform method. The following C# code illustrates this behavior:"

// Create the XslTransform object and load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(stylesheet);

// Load the file to transform.
XPathDocument doc = new XPathDocument(filename);

// Create the writer.
XmlWriter writer = XmlWriter.Create(Console.Out, xslt.OutputSettings);

// Transform the file and send the output to the console.
xslt.Transform(doc, writer);
writer.Close();

I translated with conversion Kit:

' Create the XslTransform object and load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load(stylesheet)

' Load the file to transform.
Dim doc As New XPathDocument(filename)

' Create the writer.
Dim writer As XmlWriter = XmlWriter.Create(Console.Out, xslt.OutputSettings)

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

I modified for my needs: N.B:
xml filename= Fascicolo.xml
xslt filename=Stile.xslt

output filename= fascicolo.docx

Dim xslt As New XslCompiledTransform()
xslt.Load("Stile.xslt")

' Load the file to transform.
Dim doc As New XPathDocument("Fascicolo.docx") <---- ERROR XPATH Document non Definito

' Create the writer.
Dim writer As XmlWriter = XmlWriter.Create(Console.Out, xslt.OutputSettings)

' Transform the file and send the output to the console.
xslt.Transform(doc, writer)
writer.Close()
Was it helpful?

Solution

Thanks for special collaboration Infer-On :

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

Thats run very well !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top