MSXML currently supports only XSLT 1.0.
To benefit from XSLT 2.0 under .NET environment, you need some other XSLT processors.
For some reasons, I have chosen Saxon.
Saxon provides .NET developers with a number of objects to interact with XML and XSLT.
To use Saxon without installing to GAC, you need to have all of the following 5 files and make references to the 4 dll files:
** These dll files are based on Saxon-B 9.0 for .NET.
They may be changed depending on Saxon's version (e.g. Saxon-B 9.1.0.1 - IKVM.GNU.Classpath.dll is changed to IKVM.OpenJDK.ClassLibrary.dll).
The following is a sample fragment of code for transforming XML:
using Saxon.Api
...
using (TextReader sXsl = new StreamReader("myXslFile.xslt", Encoding.UTF8)) {
Processor processor = new Processor();
XsltCompiler compiler = processor.NewXsltCompiler();
XsltTransformer transformer = compiler.Compile(sXsl).Load();
XdmNode input = processor.NewDocumentBuilder().Build(xReader); // xReader is an XmlReader object containing XML content to be transformed.
transformer.InitialContextNode = input;
Serializer serializer = new Serializer();
MemoryStream memStream = new MemoryStream();
serializer.SetOutputStream(memStream);
transformer.Run(serializer);
memStream.Position = 0;
string htmlString = string.Empty;
using(StreamReader reader = new StreamReader(memStream)){
htmlString = reader.ReadToEnd();
}
}
However, running it yields "exception.Encoding: windows-874 not found" error.
This can be solved by adding the following configuration in web.config:
<configuration>
<appSettings>
<add value="utf8" key="ikvm:file.encoding" />
</appSettings>
</configuration>
The page (with XSLT 2.0) is now rendered properly.
Resources: http://saxon.sourceforge.net/
Saxon-B is open-source.
Saxon-SA is a commercial product.
|