XsltSettings.EnableDocumentFunction

| No Comments | No TrackBacks

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

  • EnableDocumentFunction
  • EnableScript

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 {</p> <p>public static void Main () { string xsl = "&lt;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, "&lt;root/>"); GC.Collect (2); Console.WriteLine ("transform : " + wr.IsAlive); }</p> <p>static WeakReference StylesheetLoad ( XslTransform t, string xsl) { XPathDocument doc = new XPathDocument ( new StringReader (xsl)); WeakReference wr = new WeakReference (doc); t.Load (doc); return wr; }</p> <p>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.

No TrackBacks

TrackBack URL: http://veritas-vos-liberabit.com/monogatari/mt-tb.cgi/36

Leave a comment