Merge pull request #357 from Suremaker/master
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / XslTemplate.cs
index c939bd739a9e6870bcb7e3737e1451eb2f91dd10..b26b902f62048a666de60ed9c2f40c2235562adf 100644 (file)
@@ -350,9 +350,45 @@ namespace Mono.Xml.Xsl {
                                c.Input.MoveToParent ();
                        }
                }
-               
+
+               string LocationMessage {
+                       get {
+                               XslCompiledElementBase op = (XslCompiledElementBase) content;
+                               return String.Format (" from\nxsl:template {0} at {1} ({2},{3})", Match, style.BaseURI, op.LineNumber, op.LinePosition);
+                       }
+               }
+
+               void AppendTemplateFrame (XsltException ex)
+               {
+                       ex.AddTemplateFrame (LocationMessage);
+               }
+
                public virtual void Evaluate (XslTransformProcessor p, Hashtable withParams)
                {
+                       if (XslTransform.TemplateStackFrameError) {
+                               try {
+                                       EvaluateCore (p, withParams);
+                               } catch (XsltException ex) {
+                                       AppendTemplateFrame (ex);
+                                       throw ex;
+                               } catch (Exception) {
+                                       // Note that this catch causes different
+                                       // type of error to be thrown (esp.
+                                       // this causes NUnit test regression).
+                                       XsltException e = new XsltException ("Error during XSLT processing: ", null, p.CurrentNode);
+                                       AppendTemplateFrame (e);
+                                       throw e;
+                               }
+                       }
+                       else
+                               EvaluateCore (p, withParams);
+               }
+
+               void EvaluateCore (XslTransformProcessor p, Hashtable withParams)
+               {
+                       if (XslTransform.TemplateStackFrameOutput != null)
+                               XslTransform.TemplateStackFrameOutput.WriteLine (LocationMessage);
+
                        p.PushStack (stackSize);
 
                        if (parameters != null) {
@@ -431,7 +467,7 @@ namespace Mono.Xml.Xsl {
                public override void Evaluate (XslTransformProcessor p, Hashtable withParams)
                {
                        if (p.CurrentNode.NodeType == XPathNodeType.Whitespace) {
-                               if (p.PreserveWhitespace ())
+                               if (p.PreserveOutputWhitespace)
                                        p.Out.WriteWhitespace (p.CurrentNode.Value);
                        }
                        else