2003-08-14 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl.Operations / XslCallTemplate.cs
1 //
2 // XslCallTemplate.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //      
8 // (C) 2003 Ben Maurer
9 // (C) 2003 Atsushi Enomoto
10 //
11
12 using System;
13 using System.Collections;
14 using System.Xml;
15 using System.Xml.XPath;
16 using System.Xml.Xsl;
17
18 namespace Mono.Xml.Xsl.Operations {
19         public class XslCallTemplate : XslCompiledElement {
20                 XmlQualifiedName name;
21                 ArrayList withParams = new ArrayList ();
22                 public XslCallTemplate (Compiler c) : base (c) {}
23                 
24                 protected override void Compile (Compiler c)
25                 {
26                         c.AssertAttribute ("name");
27                         name = c.ParseQNameAttribute ("name");
28                         
29                         if (c.Input.MoveToFirstChild ()) {
30                                 do {
31                                         switch (c.Input.NodeType) {
32                                         case XPathNodeType.Comment:
33                                         case XPathNodeType.ProcessingInstruction:
34                                         case XPathNodeType.Whitespace:
35                                                 continue;
36                                         case XPathNodeType.Element:
37                                                 if (c.Input.NamespaceURI != XsltNamespace)
38                                                         throw new Exception ("unexptected element"); // TODO: fwd compat
39                                                 
40                                                 switch (c.Input.LocalName)
41                                                 {
42                                                         case "with-param":
43                                                                 withParams.Add (new XslVariableInformation (c));
44                                                                 break;
45                                                         default:
46                                                                 throw new Exception ("unexptected element"); // todo forwards compat
47                                                 }
48                                                 break;
49                                         default:
50                                                 throw new Exception ("unexptected node type " + c.Input.NodeType); // TODO: fwd compat
51                                         }
52                                 } while (c.Input.MoveToNext ());
53                                 c.Input.MoveToParent ();
54                         }
55                 }
56                 
57                 public override void Evaluate (XslTransformProcessor p)
58                 {
59                         Hashtable passedParams = null;
60                         
61                         if (withParams.Count > 0) {
62                                 passedParams = new Hashtable ();
63                                 foreach (XslVariableInformation param in withParams)
64                                         passedParams [param.Name] = param.Evaluate (p);
65                         }
66                         
67                         p.CallTemplate (name, passedParams);
68                 }
69         }
70 }