Saxon, famous XSLT 2.0 and XQuery processor, supports XInclude since version 8.9. But in Java version only! When I first heard about it I thought "I have good XInclude implementation for .NET in Mvp.Xml library, let's check out if Saxon on .NET works with XInclude.NET". I did some testing only to find out that they didn't play well together.
Turned out Saxon (or JAXP port to .NET, don't remember) relies on somewhat rarely used in .NET XmlReader.GetAttribute(int) method (yes, accessing attribute by index), and XIncludingReader had a bug in this method.
Finally I fixed it and so XIncludingReader from recently released Mvp.Xml library v2.3 works fine with Saxon on .NET.
Here is a little sample how to process XML Inclusions in source XML document before XSLT transformation.
using System; using Saxon.Api; using Mvp.Xml.XInclude; class Program { static void Main(string[] args) { Processor proc = new Processor(); XdmNode doc = proc.NewDocumentBuilder().Build( new XIncludingReader("d:/test/document.xml")); XsltExecutable xslt = proc.NewXsltCompiler().Compile( new Uri("d:/test/foo.xsl")); XsltTransformer trans = xslt.Load(); trans.InitialContextNode = doc; Serializer ser = new Serializer(); ser.SetOutputStream(Console.OpenStandardOutput()); trans.Run(ser); } }
Thanks,Oleg,this requirement is critical for caching purpose.
Andrey, BaseURI property should give you base URI (document where element came from) and IXmlLineInfo should give you original line/position.
Is there any means to trace source of particular node(file name) in XIncludingReader?
Thanks.
Oleg, this is fantastic! Thank you!