我正在做我的c#程序中的xslt轉換。當我在自己的運行XSLT它輸出就好了,但是當我從我的C#程序中運行它,它總是讓關:使用C#做xslt轉換忽略xsl:輸出
<?xml version="1.0" encoding="UTF-8"?>
在生成的XML文檔的頂部。我的XSLT文件看起來像:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:hd="http://www.hotdocs.com/schemas/component_library/2009"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<xsl:output method="xml" omit-xml-declaration="no" version="1.0" encoding="UTF-8"/>
<xsl:template match="/xsd:schema">
<hd:componentLibrary xmlns:hd="something" version="10">
</hd:componentLibrary>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
我運行像這樣在我的C#程序中的XSLT:
XPathDocument myXPathDoc = new XPathDocument(PathToXMLDocument);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(PathToXSLTDocument);
XmlTextWriter myWriter = new XmlTextWriter(PathToOutputLocation, null);
myXslTrans.Transform(myXPathDoc,null,myWriter);
myWriter.Close();
我已經試過沒有XSL的XSLT文檔:輸出線,但是這似乎並沒有幫助。
如何獲取輸出xml文件頂部的?xml標籤?
謝謝
'new XmlTextWriter' - 這就是2003年!你堅持使用.NET Framework 1.1嗎? – dtb 2010-09-30 17:21:59
哈,不完全。儘管使用了.NET 2.0 sp2,但仍然陷入困境。也使用VS 2005(不知道這是否相關)。決定從快速谷歌搜索使用XmlTextWriter。有更好的選擇嗎?一定要告訴! – 2010-09-30 17:25:01
[XmlWriter.Create](http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.create \(v = VS.80 \).aspx) – dtb 2010-09-30 17:26:30