2 // XslApplyTemplates.cs
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
9 // (C) 2003 Atsushi Enomoto
13 using System.Collections;
15 using System.Xml.XPath;
18 namespace Mono.Xml.Xsl.Operations {
20 public class XslApplyTemplates : XslCompiledElement {
21 XPathExpression select;
22 XmlQualifiedName mode;
23 ArrayList withParams = new ArrayList ();
25 public XslApplyTemplates (Compiler c) : base (c) {}
27 protected override void Compile (Compiler c)
29 select = c.CompileExpression (c.GetAttribute ("select"));
30 mode = c.ParseQNameAttribute ("mode");
32 if (c.Input.MoveToFirstChild ()) {
34 switch (c.Input.NodeType) {
35 case XPathNodeType.Comment:
36 case XPathNodeType.ProcessingInstruction:
37 case XPathNodeType.Whitespace:
39 case XPathNodeType.Element:
40 if (c.Input.NamespaceURI != XsltNamespace)
41 throw new Exception ("unexptected element"); // TODO: fwd compat
43 switch (c.Input.LocalName)
46 withParams.Add (new XslVariableInformation (c));
51 select = c.CompileExpression ("*");
52 c.AddSort (select, new Sort (c));
55 throw new Exception ("unexptected element"); // todo forwards compat
59 throw new Exception ("unexpected node type " + c.Input.NodeType); // todo forwards compat
61 } while (c.Input.MoveToNext ());
62 c.Input.MoveToParent ();
66 public override void Evaluate (XslTransformProcessor p)
68 Hashtable passedParams = null;
70 if (withParams.Count > 0) {
71 passedParams = new Hashtable ();
72 foreach (XslVariableInformation param in withParams)
73 passedParams [param.Name] = param.Evaluate (p);
77 p.ApplyTemplates (p.CurrentNode.SelectChildren (XPathNodeType.All), mode, passedParams);
79 p.ApplyTemplates (p.Select (select), mode, passedParams);