[Mono-bugs] [Bug 55876][Nor] Changed - NullReferenceException on Xsl Transform

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 28 Mar 2004 21:58:19 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by atsushi@ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=55876

--- shadow/55876	2004-03-27 18:13:58.000000000 -0500
+++ shadow/55876.tmp.20848	2004-03-28 21:58:19.000000000 -0500
@@ -134,6 +134,59 @@
 
 
 ------- Additional Comments From gert.driesen@pandora.be  2004-03-21 13:24 -------
 Created an attachment (id=7040)
 repro xslt
 
+
+------- Additional Comments From atsushi@ximian.com  2004-03-28 21:58 -------
+Ok, I found it is not a small bug... it is because variable binding
+expressions are evaluated latter than pushing binding context (and
+clearing actual bindings away).
+
+I simplified repro code:
+
+using System;
+using System.Xml;
+using System.Xml.Xsl;
+
+public class Test
+{
+	public static void Main ()
+	{
+		try {
+			string xml = "<root><a/></root>";
+			string xsl = @"
+<xsl:stylesheet version='1.0'
+xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
+<xsl:template match='/root'>
+<p>
+<xsl:call-template name='recurse'>
+	<xsl:with-param name='list' select='a' />
+</xsl:call-template>
+</p>
+</xsl:template>
+
+<xsl:template name='recurse'>
+<xsl:param name='list' />
+<xsl:if test='count($list)'>
+	<xsl:variable name='last' select='count($list)' />
+	<xsl:call-template name='recurse'>
+		<xsl:with-param name='list' select='$list[position()!=$last]' />
+	</xsl:call-template>
+</xsl:if>
+</xsl:template>
+</xsl:stylesheet>";
+
+			XslTransform t = new XslTransform();
+			XmlDocument xsldoc = new XmlDocument ();
+			xsldoc.LoadXml (xsl);
+			t.Load (xsldoc);
+			XmlDocument doc = new XmlDocument ();
+			doc.LoadXml (xml);
+			t.Transform (doc, null, Console.Out);
+		} catch (Exception ex) {
+			Console.WriteLine (ex);
+		}
+	}
+}
+