http://bugzilla.novell.com/show_bug.cgi?id=559987
http://bugzilla.novell.com/show_bug.cgi?id=559987#c0 Summary: Can't use XDocument as a node-set source in XSLT Classification: Mono Product: Mono: Class Libraries Version: SVN Platform: x86-64 OS/Version: openSUSE 11.2 Status: NEW Severity: Normal Priority: P5 - None Component: Sys.XML AssignedTo: [email protected] ReportedBy: [email protected] QAContact: [email protected] Found By: --- Blocker: --- (This is related to https://bugzilla.novell.com/show_bug.cgi?id=559957, but with an XDocument instead of an XmlDocument.) If you use an XPathNavigator backed by an XDocument (instead of an XmlDocument), the XSLT doesn't work. Consider: using System; using System.IO; using System.Xml; using System.Xml.Linq; using System.Xml.XPath; using System.Xml.Xsl; class Test { public static void Main () { string xsl = @"<xsl:stylesheet version='1.0' exclude-result-prefixes='msxsl' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:msxsl='urn:schemas-microsoft-com:xslt' > <xsl:param name='Index' /> <xsl:template match='/'> <root> <xsl:variable name='t'> <xsl:call-template name='get-bar'> <xsl:with-param name='type' select=""'Mono.DocTest.Color'"" /> </xsl:call-template> </xsl:variable> <xsl:value-of select='msxsl:node-set($t)/Type/@Name' /> </root> </xsl:template> <xsl:template name='get-bar'> <xsl:param name='type' /> <xsl:for-each select='$Index/Types/Namespace/Type'> <xsl:variable name='nsp'> <xsl:choose> <xsl:when test='string-length (parent::Namespace/@Name) = 0' /> <xsl:otherwise> <xsl:value-of select='parent::Namespace/@Name' /> <xsl:text>.</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:if test=""concat($nsp, translate(@Name, '+', '.')) = $type""> <Type Name='{...@name}' Namespace='{parent::Namespace/@Name}' /> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>"; var overview = new XDocument ( new XElement ("Overview", new XElement ("Types", new XElement ("Namespace", new XAttribute ("Name", "Mono.DocTest"), new XElement ("Type", new XAttribute ("Name", "Color"), new XAttribute ("Kind", "Enumeration")))))); var args = new XsltArgumentList (); args.AddParam ("Index", "", overview.CreateNavigator ()); var t = new XslCompiledTransform (); t.Load (new XPathDocument (new StringReader (xsl))); t.Transform ( new XPathDocument ( new XmlTextReader ( new StringReader ( "<root><foo attr='A'/><foo attr='B'/><foo attr='C'/></root>"))), args, Console.Out); Console.WriteLine(); } } The above source differs from https://bugzilla.novell.com/show_bug.cgi?id=559957 in two ways: 1. The XPath expression is $Index/Types/Namespace/Type (i.e. the buggy Mono behavior which should be replaced with $Index/Overview/Types/Namespace/Type for NET use) 2. We're using an XDocument instead of an XmlDocument to provide the XPathNavigator. The problem is the output: <?xml version="1.0" encoding="utf-8"?><root></root> It should be '<root>Color</root>'; if we fix the XPath expression on line 30 (in accordance with #559957), .NET generates: <?xml version="1.0" encoding="IBM437"?><root>Color</root> In fact, I can't find any way to get an XDocument-backed XPathNavigator to actually generate correct output with this app. Worst of all is if I use the workaround listed in #559957 (change line 30 to select='$Index//Type'), it crashes with a NullReferenceException: $ gmcs eno.cs -r:System.Xml.Linq && mono eno.exe <?xml version="1.0" encoding="utf-8"?><root Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at System.Xml.Linq.XNodeNavigator.get_NodeType () [0x00000] in <filename unknown>:0 at System.Xml.XPath.NodeNameTest.Match (IXmlNamespaceResolver nsm, System.Xml.XPath.XPathNavigator nav) [0x00000] in <filename unknown>:0 at System.Xml.XPath.AxisIterator.MoveNextCore () [0x00000] in <filename unknown>:0 at System.Xml.XPath.BaseIterator.MoveNext () [0x00000] in <filename unknown>:0 at System.Xml.XPath.SlashIterator.MoveNextCore () [0x00000] in <filename unknown>:0 at System.Xml.XPath.BaseIterator.MoveNext () [0x00000] in <filename unknown>:0 at System.Xml.XPath.SortedIterator..ctor (System.Xml.XPath.BaseIterator iter) [0x00000] in <filename unknown>:0 at System.Xml.XPath.ExprSLASH.Evaluate (System.Xml.XPath.BaseIterator iter) [0x00000] in <filename unknown>:0 at System.Xml.XPath.Expression.EvaluateNodeSet (System.Xml.XPath.BaseIterator iter) [0x00000] in <filename unknown>:0 at System.Xml.XPath.CompiledExpression.EvaluateNodeSet (System.Xml.XPath.BaseIterator iter) [0x00000] in <filename unknown>:0 at System.Xml.XPath.XPathNavigator.Select (System.Xml.XPath.XPathExpression expr, IXmlNamespaceResolver ctx) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTransformProcessor.Select (System.Xml.XPath.XPathExpression expr) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslForEach.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslTemplateContent.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTemplate.EvaluateCore (Mono.Xml.Xsl.XslTransformProcessor p, System.Collections.Hashtable withParams) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTemplate.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p, System.Collections.Hashtable withParams) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTransformProcessor.CallTemplate (System.Xml.XmlQualifiedName name, System.Collections.ArrayList withParams) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslCallTemplate.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslTemplateContent.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslVariableInformation.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslLocalVariable.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslTemplateContent.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslLiteralElement.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.Operations.XslTemplateContent.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTemplate.EvaluateCore (Mono.Xml.Xsl.XslTransformProcessor p, System.Collections.Hashtable withParams) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTemplate.Evaluate (Mono.Xml.Xsl.XslTransformProcessor p, System.Collections.Hashtable withParams) [0x00000] in <filename unknown>:0 at Mono.Xml.Xsl.XslTransformProcessor.ApplyTemplates (System.Xml.XPath.XPathNodeIterator nodes, System.Xml.XmlQualifiedName mode, System.Collections.ArrayList withParams) [0x00000] in <filename unknown>:0 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] in <filename unknown>:0 at System.Xml.Xsl.XslCompiledTransform.Transform (System.Xml.XPath.XPathNavigator input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output) [0x00000] in <filename unknown>:0 at System.Xml.Xsl.XslCompiledTransform.Transform (IXPathNavigable input, System.Xml.Xsl.XsltArgumentList args, System.IO.TextWriter output) [0x00000] in <filename unknown>:0 at Test.Main () [0x00000] in <filename unknown>:0 Apparently XLinq + XSLT == FAIL at the moment. -- Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
