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 {
19 public class XslChoose : XslCompiledElement {
20 XslOperation defaultChoice = null;
21 ArrayList conditions = new ArrayList ();
23 public XslChoose (Compiler c) : base (c) {}
25 protected override void Compile (Compiler c)
27 if (!c.Input.MoveToFirstChild ()) throw new Exception ("Expecting non-empty element");
30 if (c.Input.NodeType != XPathNodeType.Element) continue;
31 if (c.Input.NamespaceURI != XsltNamespace) continue;
33 if (defaultChoice != null)
34 throw new Exception ("otherwise attribute must be last");
36 switch (c.Input.LocalName) {
38 conditions.Add (new XslIf (c));
42 if (c.Input.MoveToFirstChild ()) {
43 defaultChoice = c.CompileTemplateContent ();
44 c.Input.MoveToParent ();
49 break; // TODO: forwards compat
51 } while (c.Input.MoveToNext ());
53 c.Input.MoveToParent ();
55 if (conditions.Count == 0)
56 throw new Exception ("Choose must have 1 or ore when elements");
59 public override void Evaluate (XslTransformProcessor p)
61 foreach (XslIf test in conditions) {
62 if (test.EvaluateIfTrue (p))
65 if (defaultChoice != null)
66 defaultChoice.Evaluate (p);