[Mono-bugs] [Bug 82493][Maj] New - bug in xslt extension object

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Aug 20 05:26:30 EDT 2007


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 stm at dbc.dk.

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

--- shadow/82493	2007-08-20 05:26:30.000000000 -0400
+++ shadow/82493.tmp.21260	2007-08-20 05:26:30.000000000 -0400
@@ -0,0 +1,224 @@
+Bug#: 82493
+Product: Mono: Class Libraries
+Version: 1.2
+OS: 
+OS Details: Linux ubis 2.6.17-10-server #2 SMP Tue Dec 5 22:29:32 UTC 2006 i686 GNU/Linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: Sys.XML
+AssignedTo: atsushi at ximian.com                            
+ReportedBy: stm at dbc.dk               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: bug in xslt extension object
+
+Description of Problem:
+While building an XmlTransformation class that can embed external objects
+into the xsl transformation process via System.Xml.Xsl.XsltArgumentList I've
+hit a possible bug in the mono stack. I've attached a test program, a text
+xsl file and a test xml document. Running the program under mono 1.2.5
+(/trunk/ r84242) (the program was compiled with Mono C# compiler version
+1.2.5.0) with --debug gives me:
+
+Unhandled Exception: System.Xml.Xsl.XsltException: Custom function reported
+an error. ---> System.InvalidCastException: Cannot cast from source type to
+destination type.
+  at Mono.Xml.Xsl.XsltExtensionFunction.Invoke
+(Mono.Xml.Xsl.XsltCompiledContext xsltContext, System.Object[] args,
+System.Xml.XPath.XPathNavigator docContext) [0x00000] --- End of inner
+exception stack trace ---
+
+  at Mono.Xml.Xsl.XsltExtensionFunction.Invoke
+(Mono.Xml.Xsl.XsltCompiledContext xsltContext, System.Object[] args,
+System.Xml.XPath.XPathNavigator docContext) [0x00000]
+  at Mono.Xml.Xsl.XPFuncImpl.Invoke (System.Xml.Xsl.XsltContext xsltContext,
+System.Object[] args, System.Xml.XPath.XPathNavigator docContext) [0x00000]
+  at System.Xml.XPath.ExprFunctionCall.Evaluate
+(System.Xml.XPath.BaseIterator iter) [0x00000]
+  at System.Xml.XPath.Expression.EvaluateString
+(System.Xml.XPath.BaseIterator iter) [0x00000]
+  at System.Xml.XPath.CompiledExpression.EvaluateString
+(System.Xml.XPath.BaseIterator iter) [0x00000]
+  at System.Xml.XPath.XPathNavigator.EvaluateString
+(System.Xml.XPath.XPathExpression expr, System.Xml.XPath.XPathNodeIterator
+context, IXmlNamespaceResolver ctx) [0x00000]
+  at Mono.Xml.Xsl.XslTransformProcessor.EvaluateString
+(System.Xml.XPath.XPathExpression expr) [0x00000]
+  at Mono.Xml.Xsl.Operations.XslValueOf.Evaluate
+(Mono.Xml.Xsl.XslTransformProcessor p) [0x00000]
+  at Mono.Xml.Xsl.Operations.XslTemplateContent.Evaluate
+(Mono.Xml.Xsl.XslTransformProcessor p) [0x00000]
+  at Mono.Xml.Xsl.XslTemplate.EvaluateCore
+(Mono.Xml.Xsl.XslTransformProcessor p, System.Collections.Hashtable
+withParams) [0x00000]
+  at Mono.Xml.Xsl.XslTemplate.Evaluate (Mono.Xml.Xsl.XslTransformProcessor
+p, System.Collections.Hashtable withParams) [0x00000]
+  at Mono.Xml.Xsl.XslTransformProcessor.ApplyTemplates
+(System.Xml.XPath.XPathNodeIterator nodes, System.Xml.XmlQualifiedName mode,
+System.Collections.ArrayList withParams) [0x00000]
+  at Mono.Xml.Xsl.XslTransformProcessor.Process
+(System.Xml.XPath.XPathNavigator root, Mono.Xml.Xsl.Outputter outputtter,
+System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlResolver resolver)
+[0x00000]
+  at System.Xml.Xsl.XslTransform.Transform (System.Xml.XPath.XPathNavigator
+input, System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output,
+System.Xml.XmlResolver resolver) [0x00000]
+  at System.Xml.Xsl.XslTransform.Transform (IXPathNavigable input,
+System.Xml.Xsl.XsltArgumentList args, System.Xml.XmlWriter output,
+System.Xml.XmlResolver resolver) [0x00000]
+  at XmlTransformExtObj.Transform (System.String stylesheetfilename,
+System.String inxml) [0x00000]
+  at XmlTransformExtObj.Main (System.String[] args) [0x00000]
+
+running the program under Microsoft Windows .Net Framework v2.0.50727 (the
+program was compiled with Microsoft (R) Visual C# 2005 Compiler version
+8.00.50727.42) gives me:
+
+210297.Net for monkeys must be returned now!
+  .Net for goldfish must be returned now!
+
+...as was expected.
+
+Steps to reproduce the problem:
+1. compile XmlTransformExtObj.cs into an executable
+2. run 'mono XmlTransformExtObj.exe recall_extension_object.xsl
+recall_extension_object.xml'
+
+Actual Results:
+System.InvalidCastException (see above or attached debug information for a
+more verbose variant)
+
+Expected Results:
+210297.Net for monkeys must be returned now!
+  .Net for goldfish must be returned now! (i.e. the injection of the
+external object into the xsl transformation process)
+
+How often does this happen? 
+Always
+
+Additional Information:
+As mentioned above, the program run as should be expected under .Net
+framework, and as the point of code where the exception is thrown also
+contains the comment:
+
+//Debug.WriteLine ("****** INCORRECT RESOLUTION **********");
+
+I reckon that this bug was somehow anticipated.
+I would very much have liked to provide the files as attachments, but this
+instance of bugzilla wouldn't let me. Instead, to avoid clubbering of the
+above description, I here provide the three files needed to reproduce the bug:
+
+XmlTransformExtObj.cs:
+----------------------
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Xsl;
+
+public static class XmlTransformExtObj{
+
+  public static int Main( String[] args ){
+    if ( args.Length != 2 ) {
+      Console.WriteLine( "Usage: XmlTransformExtObj.exe <stylesheet>
+<xmldocument>" );
+      return -1;
+    }
+    string stylesheet    = args[0];
+    string xmldocument   = args[1];
+
+    XmlTransformExtObj.Transform(stylesheet, xmldocument);
+
+    return 0;
+  }
+  public static void Transform( string stylesheetfilename, string inxml ){
+    //create XslTransform object, and load stylesheet
+    XslTransform transformationObj = new XslTransform();
+    transformationObj.Load( stylesheetfilename );
+
+    //load xml
+    XmlDocument doc = new XmlDocument();
+    doc.Load( inxml );
+
+    //construct the xsl extension object
+    XslExtensionClass GetCalculation = new XslExtensionClass(  "a4" );
+
+    //...and a list to hold it in
+    XsltArgumentList xslExtensionArgList = new XsltArgumentList();
+
+    // the namespace must match the namespace given in the xsl
+    xslExtensionArgList.AddExtensionObject( "urn:e", GetCalculation );
+
+    //Create an XmlTextWriter to output to the console.
+    XmlTextWriter writer = new XmlTextWriter(Console.Out);
+
+    transformationObj.Transform( doc, xslExtensionArgList, writer, null );
+//     transformationObj.Transform( doc, null, Console.Out );
+  }
+
+  public class XslExtensionClass{
+
+    private string paperType = String.Empty;
+
+    public XslExtensionClass( string paperType ){
+      this.paperType = paperType;
+    }
+
+  /// <summary>GetPageDimensions is a helper method, which returns
+  /// the dimensions of a page given the specification of a
+  /// papertype</summary> <description>GetPageDimensions is used by
+  /// XmlArgumentList.AddExtensionObject, which in turn is called
+  /// from the xslt that is processed by the XslTransform.Transform
+  /// method. </description>
+  /// <returns>An integer list of the dimensions (width,
+  /// height)</returns>
+  /// <param name="paperType">A string describing the papertype,
+  /// e.g. a4</param>
+
+    public int GetPageDimensions(){
+      switch( this.paperType ){
+        // paper sizes gotten from http://en.wikipedia.org/wiki/Paper_size
+      case "a4":{
+        return 210297;
+      }
+      case "letter":{
+        return 216279;
+      }
+      default:{
+        throw new ArgumentException("Unknown page size type: "+this.paperType);
+      }
+      }
+    }
+  }
+}
+-------------------------------------------------------------------------
+recall_extension_object.xml:
+----------------------------
+<?xml version="1.0" encoding="utf-8"?>
+<recall>
+  <book>
+    <title>.Net for monkeys</title>
+    <isbn>123465789</isbn>
+  </book>
+  <book>
+    <title>.Net for goldfish</title>
+    <isbn>987654321</isbn>
+  </book>
+</recall>
+----------------------------------------------------------------
+recall_extension_object.xsl:
+----------------------------
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:ExtObject="urn:e">
+<xsl:template match="/">
+   <xsl:value-of select="ExtObject:GetPageDimensions()"/>
+  <xsl:for-each select="recall/book">
+    <xsl:value-of select="title"/> must be returned now!
+  </xsl:for-each>
+</xsl:template>
+</xsl:stylesheet>


More information about the mono-bugs mailing list