2014-01-22 34 views

回答

1

在Sourceforge和www.saxonica.com上提供的撒克遜資源下載中查找XsltExamples.cs。第一個例子似乎正在做你所要求的。

public static void ExampleSimple1(String sourceUri, String xsltUri) { 

     // Create a Processor instance. 
     Processor processor = new Processor(); 

     // Load the source document 
     XdmNode input = processor.NewDocumentBuilder().Build(new Uri(sourceUri)); 

     // Create a transformer for the stylesheet. 
     XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(xsltUri)).Load(); 

     // Set the root node of the source document to be the initial context node 
     transformer.InitialContextNode = input; 

     // Create a serializer 
     Serializer serializer = new Serializer(); 
     serializer.SetOutputWriter(Console.Out); 

     // Transform the source XML to System.out. 
     transformer.Run(serializer); 
    } 
+0

完美!我會給你買一瓶啤酒,非常感謝你。 – cysus

0

是否使用XmlDocument對象用於讀取XML?如果是這樣,您需要XMLDocument.Load()方法,該方法可以將文件路徑或URL,TextReader或Stream作爲輸入。

同樣,XDocument.Load()(msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.load(v=vs.110).aspx)也有一組類似的重載。

+0

直到現在我正在用上面的鏈接給出的本地文件進行測試。我想從URL Webservice中檢索xml,比如mydomain.com/Mixer?somevars – cysus

+0

是的 - 這是相同的字符串重載,只是使用URL! – ttrmw

+0

如果可以避免,則不需要構建XmlDocument(DOM)。撒克遜將接受來自DOM的輸入,但使用撒克遜的本地樹表示法效率更高(快10倍)。 –