[Mono-bugs] [Bug 560002] New: Element-backed node-sets can't be used within XSLT.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Dec 2 12:57:29 EST 2009



           Summary: Element-backed node-sets can't be used within 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: atsushi at ximian.com
        ReportedBy: jpryor at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

https://bugzilla.novell.com/show_bug.cgi?id=559957  for elements, not

Consider the following program:

  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' 
    <xsl:param name='Index' />
    <xsl:template match='/'>
      <xsl:variable name='t'>
        <xsl:call-template name='get-bar'>
          <xsl:with-param name='type' select=""'Mono.DocTest.Color'"" />
      <xsl:value-of select='msxsl:node-set($t)/Type/@Name' />
    <xsl:template name='get-bar'>
      <xsl:param name='type' />
      <xsl:for-each select='$Index/Types/Namespace/Type'>
        <xsl:variable name='nsp'>
            <xsl:when test='string-length (parent::Namespace/@Name) = 0' />
              <xsl:value-of select='parent::Namespace/@Name' />
        <xsl:if test=""concat($nsp, translate(@Name, '+', '.')) = $type"">
          <Type Name='{@Name}' Namespace='{parent::Namespace/@Name}' />
      var overview = GetOverview ();
      var args = new XsltArgumentList ();
      args.AddParam ("Index", "", overview.DocumentElement.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

    static XmlDocument GetOverview ()
      var doc = new XmlDocument ();

      var overview = doc.CreateElement ("Overview");
      doc.AppendChild (overview);

      var types = doc.CreateElement ("Types");
      overview.AppendChild (types);

      var ns = doc.CreateElement ("Namespace");
      types.AppendChild (ns);
      var name = doc.CreateAttribute ("Name");
      name.Value = "Mono.DocTest";
      ns.Attributes.Append (name);

      var t = doc.CreateElement ("Type");
      ns.AppendChild (t);

      name = doc.CreateAttribute ("Name");
      name.Value = "Color";
      t.Attributes.Append (name);
      var k = doc.CreateAttribute ("Kind");
      k.Value = "Enumeration";
      t.Attributes.Append (k);

      return doc;

Under Mono, this prints:

  <?xml version="1.0" encoding="utf-8"?><root></root>

NET prints:

  <?xml version="1.0" encoding="IBM437"?><root>Color</root>

[Aside: Why does .NET default to IBM437 as the code page?!]

Notice that .NET finds the $Index/Types/Namespace/Type node (from the XPath on
line 30), while Mono does not.

As with #559957, the workaround under Mono is to use $Index//Type.

If we take a page out of https://bugzilla.novell.com/show_bug.cgi?id=559987,
and use an XElement-backed XPathNavigator (replacing line 46-48 with the

      var overview = new XElement ("Overview",
            new XElement ("Types",
              new XElement ("Namespace", new XAttribute ("Name",
                new XElement ("Type", new XAttribute ("Name", "Color"),
                  new XAttribute ("Kind", "Enumeration")))));
      var args = new XsltArgumentList ();
      args.AddParam ("Index", "", overview.CreateNavigator ());

Mono generates the same wrong output as with the above overview.DocumentElement
(for an XPath on line 30 of $Index/Types/Namespace/Type), while .NET produces
the same correct output as with the above overview.DocumentElement code.

Furthermore, just as in #559987, if we change line 30 to be $Index//Type, we
get a NullReferenceException with what looks like the same stack trace.

Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list