How to use XSLT in .NET?

I am going to translate an XML document into another XML document based on Excel language conversion. Where can I find good tutorials on how to do this in .NET?

I found something about how to do this using open source tools. But what about the .NET platform? Just a few other quick questions ...

  • Can someone please give me a quick and dirty explanation of the order of XSLT operations? Am I still a little confused about what is going on?

  • Are there any explicit .NET tools for working with XSLT? I know that when working with XSLT, XSD, and XML files, you get a small XML drop-down list in the main menu of Visual Studio .NET. I suppose that is good now, but it would be nice to know if I have other options.

  • I'm not going to actually convert the files ... Well, I think Extensible Stylesheet will be a file, but I want to import an XML string, convert it to another XML string, and then through to view it in the MVC design pattern. How can i do this?

+3
source share
1 answer

1) can someone please give me a quick and dirty explanation of the order of XSLT operations? Am I still a little confused about what is going on?

In terms of usage, there is only one operation: you capture some input, and the XSLT engine converts it to output.

2) - .Net XSLT? , XSLT, XSD XML XML Visual studio.net. , , , .

XslCompiledTransform XSL-.

3) ... , , Extensible Style , xml, xml, MVC. - - ? , - ?

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

, (...)?

XSLT, : " xslt-?" .

+7

All Articles