public override XPathResultType ReturnType {
get { return expr.ReturnType; }
}
-
- public override bool RequireSorting {
- get { return true; }
- }
}
internal class XslKey
QName name;
CompiledExpression useExpr;
Pattern matchPattern;
-// Hashtable map;
-// Hashtable mappedDocuments;
public XslKey (Compiler c)
{
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 {
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 ();
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 =
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