monogatari

« NvdlValidatingReader | Main | .NET developers want inconsistent schema validity on xml:* attributes? »

XsltSettings.EnableDocumentFunction

This is a short followup for XslCompiledTransform. It accepts a new optional argument XsltSettings. It is an enum that holds two switches:

There is a reason why document("") could be optional. When document() function receives an empty string argument, it returns a node-set that contains the stylesheet itself. That however means, XSLT engine must preserve reference to the input stylesheet document (XPathNavigator). There was a bug report to MS feedback that document() could not be resolved (I once refered to it). So this options looks like Microsoft's response to developers' need.

I thought that not keeping source document is a good idea, so I tried to remove all the references to XPathNavigator clones in our XslTransform (except for document() function). After some hacking, I wrote a simple test which assures that XslTransform does not have reference to the document:

using System; using System.IO; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; class Test { public static void Main () { string xsl = "<xsl:transform " + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'" + " version='1.0'/>"; XslTransform t = new XslTransform (); WeakReference wr = StylesheetLoad (t, xsl); GC.Collect (2); Console.WriteLine ("load : " + wr.IsAlive); wr = StylesheetTransform (t, "<root/>"); GC.Collect (2); Console.WriteLine ("transform : " + wr.IsAlive); } static WeakReference StylesheetLoad ( XslTransform t, string xsl) { XPathDocument doc = new XPathDocument ( new StringReader (xsl)); WeakReference wr = new WeakReference (doc); t.Load (doc); return wr; } static WeakReference StylesheetTransform ( XslTransform t, string xml) { XPathDocument doc = new XPathDocument ( new StringReader (xml)); WeakReference wr = new WeakReference (doc); t.Transform (doc, null, TextWriter.Null, null); return wr; } }

So I tried it under Windows:

$ csc test.cs /nologo /nowarn:618
$ mono test.exe
load : False
transform : False
$ ./test
load : True
transform : False

Hmm... I wonder if I missed something.

|