Xsl:输出元素和Xml:writer

时间:2014-05-14 06:15:11

标签: c# visual-studio xslt visual-studio-2008

我创建了此表单以使用XSLT文件转换XML文件并创建DOC文件。 通常我使用Word打开我的XML文件,然后选择一个XSLT文件,然后在创建一个带有Style的doc文件之后。

结束页面的代码在C#中你可以帮我在Visual Basic 2008中翻译吗?

enter image description here

"当转换输出发送到XmlWriter对象时,XslTransform类忽略了xsl:output设置。 XslCompiledTransform类具有OutputSettings属性,该属性返回XmlWriterSettings对象,该对象包含从样式表的xsl:output元素派生的输出信息。 XmlWriterSettings对象用于创建具有可传递给Transform方法的正确设置的XmlWriter对象。以下C#代码说明了这种行为:"

// 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();

我翻译了转换套件:

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

我根据自己的需要进行了修改: N.B:
xml filename = Fascicolo.xml
xslt filename = Stile.xslt

输出文件名= 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()

1 个答案:

答案 0 :(得分:1)

感谢特别合作推断:

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

多数人跑得很好!