2014-01-22 33 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倍)。 –