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;
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 if (withParams == null) withParams = new ArrayList ();
47 withParams.Add (new XslVariableInformation (c));
52 select = c.CompileExpression ("*");
53 c.AddSort (select, new Sort (c));
56 throw new Exception ("unexptected element"); // todo forwards compat
60 throw new Exception ("unexpected node type " + c.Input.NodeType); // todo forwards compat
62 } while (c.Input.MoveToNext ());
63 c.Input.MoveToParent ();
67 public override void Evaluate (XslTransformProcessor p)
70 p.ApplyTemplates (p.CurrentNode.SelectChildren (XPathNodeType.All), mode, withParams);
72 p.ApplyTemplates (p.Select (select), mode, withParams);