XPathExpression select;
XmlQualifiedName mode;
ArrayList withParams;
-
+ XslSortEvaluator sortEvaluator;
+
public XslApplyTemplates (Compiler c) : base (c) {}
protected override void Compile (Compiler c)
{
select = c.CompileExpression (c.GetAttribute ("select"));
mode = c.ParseQNameAttribute ("mode");
-
+ ArrayList sorterList = null;
if (c.Input.MoveToFirstChild ()) {
do {
switch (c.Input.NodeType) {
continue;
case XPathNodeType.Element:
if (c.Input.NamespaceURI != XsltNamespace)
- throw new XsltCompileException ("unexptected element", null, c.Input); // TODO: fwd compat
+ throw new XsltCompileException ("Unexpected element", null, c.Input); // TODO: fwd compat
switch (c.Input.LocalName)
{
break;
case "sort":
+ if (sorterList == null)
+ sorterList = new ArrayList ();
if (select == null)
select = c.CompileExpression ("*");
- c.AddSort (select, new Sort (c));
+ sorterList.Add (new Sort (c));
+ //c.AddSort (select, new Sort (c));
break;
default:
- throw new XsltCompileException ("unexptected element", null, c.Input); // todo forwards compat
+ throw new XsltCompileException ("Unexpected element", null, c.Input); // todo forwards compat
}
break;
default:
- throw new XsltCompileException ("unexpected node type " + c.Input.NodeType, null, c.Input); // todo forwards compat
+ throw new XsltCompileException ("Unexpected node type " + c.Input.NodeType, null, c.Input); // todo forwards compat
}
} while (c.Input.MoveToNext ());
c.Input.MoveToParent ();
}
+ if (sorterList != null)
+ sortEvaluator = new XslSortEvaluator (select,
+ (Sort []) sorterList.ToArray (typeof (Sort)));
}
public override void Evaluate (XslTransformProcessor p)
{
if (select == null)
p.ApplyTemplates (p.CurrentNode.SelectChildren (XPathNodeType.All), mode, withParams);
- else
- p.ApplyTemplates (p.Select (select), mode, withParams);
+ else {
+ XPathNodeIterator iter = sortEvaluator != null ?
+ sortEvaluator.SortedSelect (p) :
+ p.Select (select);
+ p.ApplyTemplates (iter, mode, withParams);
+ }
}
}
}