我发现了一些关于如何使用开源工具进行操作的内容.但是.NET框架呢?只是其他一些快速问题……
>有人可以给我一个关于XSLT操作顺序的快速而肮脏的解释吗?我对发生的事情仍然有点困惑?
>是否有用于使用XSLT的显式.NET工具?我知道在使用XSLT,XSD和XML文件时,您会在Visual Studio .NET的主菜单上获得一个XML下拉列表.我想现在还可以,但是知道我是否有其他选择会很高兴.
>我不会真正转换文件……好吧,我猜可扩展样式表将是一个文件,但我想导入一个XML字符串,将其转换为另一个XML字符串,然后通过它转换为一个视图MVC设计模式.我怎样才能做到这一点?
1) could somebody please give me a quick and dirty explanation of the XSLT order of operations? I am still a little confused about what happens?
从使用的角度来看,只有一个操作:你获取一些输入,XSLT引擎将它转换为输出.
2) are there any explicit .Net tools for working with XSLT’s? I know that when working with XSLT’s, XSD’s, and XML files you get a little XML drop down list on the main menu of Visual studio .net. I guess that is ok for now, but it would be nice to know if I had other options.
使用XslCompiledTransform
,您可以应用XSL转换.
3) I am not going to be actually transforming files… Well, I guess the Extensible Style sheet will be a file, but I want to import a xml string, transform it to another xml string, and then through that out to a view in the MVC design pattern. Anybody every try anything crazy like that before? If so, any advice?
我上面提到的XslCompiledTransform类可以直接在流,XmlReader和XmlWriter对象上工作,因此您可以在内存中完成所有操作,而无需任何临时文件.
这是一个基本的例子:
// Load the XSL transform from a file var transform = new XslCompiledTransform(); transform.Load("foo.xslt"); // This is your input string string input = /* blah */; // Make an XML reader out of the string XmlReader inputXmlReader; using(var inputReader = new StringReader(input)) { inputXmlReader = XmlReader.Create(inputReader); } using(writer = new StringWriter()) // prepare a string writer for the output { // if you need to pass arguments to the XSLT... var args = new XsltArgumentList(); args.AddParam("key", "urn:xml-namespace-of-key", "value"); // Apply the transformation to the reader and write it in our string writer transform.Transform(inputXmlReader, args, writer); // Retrieve the output string from the string writer return writer.GetStringBuilder().ToString(); }
Where can I find good tutorials about how to do this (…)?
如果您想学习XSLT语言本身,可以查看以前的问题:“How to get started with xslt-transformations?”.