* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl / XslKey.cs
index b1c618262746c014ae9eef14629b10c8abf14990..1e97bf03ee58b0e77a9c543edc748045ba52f518 100644 (file)
@@ -67,10 +67,6 @@ namespace Mono.Xml.Xsl
                public override XPathResultType ReturnType {
                        get { return expr.ReturnType; }
                }
-
-               public override bool RequireSorting {
-                       get { return true; }
-               }
        }
 
        internal class XslKey
@@ -78,8 +74,6 @@ namespace Mono.Xml.Xsl
                QName name;
                CompiledExpression useExpr;
                Pattern matchPattern;
-//             Hashtable map;
-//             Hashtable mappedDocuments;
 
                public XslKey (Compiler c)
                {
@@ -125,19 +119,37 @@ namespace Mono.Xml.Xsl
                        nav.MoveToRoot ();
                        XPathNavigator tmp = doc.Clone ();
 
+                       bool matchesAttributes = false;
+                       switch (key.Match.EvaluatedNodeType) {
+                       case XPathNodeType.All:
+                       case XPathNodeType.Attribute:
+                               matchesAttributes = true;
+                               break;
+                       }
+
                        do {
                                if (key.Match.Matches (nav, ctx)) {
                                        tmp.MoveTo (nav);
                                        CollectIndex (nav, tmp);
                                }
-                       } while (MoveNavigatorToNext (nav));
+                       } while (MoveNavigatorToNext (nav, matchesAttributes));
                        if (map != null)
                                foreach (ArrayList list in map.Values)
                                        list.Sort (XPathNavigatorComparer.Instance);
                }
 
-               private bool MoveNavigatorToNext (XPathNavigator nav)
+               private bool MoveNavigatorToNext (XPathNavigator nav, bool matchesAttributes)
                {
+                       if (matchesAttributes) {
+                               if (nav.NodeType != XPathNodeType.Attribute &&
+                                       nav.MoveToFirstAttribute ())
+                                       return true;
+                               else if (nav.NodeType == XPathNodeType.Attribute) {
+                                       if (nav.MoveToNextAttribute ())
+                                               return true;
+                                       nav.MoveToParent ();
+                               }
+                       }
                        if (nav.MoveToFirstChild ())
                                return true;
                        do {
@@ -215,22 +227,6 @@ namespace Mono.Xml.Xsl
                public BaseIterator Evaluate (BaseIterator iter,
                        Expression valueExpr)
                {
-                       /*
-                       ArrayList result = new ArrayList ();
-                       object o = valueExpr.Evaluate (iter);
-                       XPathNodeIterator it = o as XPathNodeIterator;
-                       XsltContext ctx = iter.NamespaceManager as XsltContext;
-
-                       if (it != null) {
-                               while (it.MoveNext())
-                                       FindKeyMatch (it.Current.Value, result, iter.Current, ctx);
-                       } else {
-                               FindKeyMatch (XPathFunctions.ToString (o), result, iter.Current, ctx);
-                       }
-                       result.Sort (XPathNavigatorComparer.Instance);
-                       return new ListIterator (result, (ctx));
-                       */
-
                        XPathNodeIterator i = iter;
                        if (iter.CurrentPosition == 0) {
                                i = iter.Clone ();
@@ -247,7 +243,7 @@ namespace Mono.Xml.Xsl
                        if (it != null) {
                                while (it.MoveNext()) {
                                        ArrayList nodes = GetNodesByValue (
-                                               it.Current, it.Current.Value, ctx);
+                                               nav, it.Current.Value, ctx);
                                        if (nodes == null)
                                                continue;
                                        ListIterator tmp =
@@ -268,45 +264,5 @@ namespace Mono.Xml.Xsl
 
                        return result != null ? result : new NullIterator (iter);
                }
-               
-               /*
-               void FindKeyMatch (string value, ArrayList result, XPathNavigator context, XsltContext xsltContext)
-               {
-                       XPathNavigator searchDoc = context;//.Clone ();
-                       searchDoc.MoveToRoot ();
-                       if (key != null) {
-                               XPathNodeIterator desc = searchDoc.SelectDescendants (XPathNodeType.All, true);
-
-                               while (desc.MoveNext ()) {
-                                       if (Matches (desc.Current, value, xsltContext))
-                                               AddResult (result, desc.Current);
-                                       
-                                       if (!desc.Current.MoveToFirstAttribute ())
-                                               continue;
-                                       do {
-                                               if (Matches (desc.Current, value, xsltContext))
-                                                       AddResult (result, desc.Current);       
-                                       } while (desc.Current.MoveToNextAttribute ());
-                                       
-                                       desc.Current.MoveToParent ();
-                               }
-                       }
-               }
-
-               void AddResult (ArrayList result, XPathNavigator nav)
-               {
-                       for (int i = 0; i < result.Count; i++) {
-                               XmlNodeOrder docOrder = nav.ComparePosition (((XPathNavigator)result [i]));
-                               if (docOrder == XmlNodeOrder.Same)
-                                       return;
-                               
-                               if (docOrder == XmlNodeOrder.Before) {
-                                       result.Insert(i, nav.Clone ());
-                                       return;
-                               }
-                       }
-                       result.Add (nav.Clone ());
-               }
-               */
        }
 }
\ No newline at end of file