2003-12-20 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl.Operations / XslIf.cs
1 //
2 // XslIf.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         // also applicable to xsl:when
20         public class XslIf : XslCompiledElement {
21                 XPathExpression test;
22                 XslOperation children;
23                 
24                 public XslIf (Compiler c) : base (c) {}
25                 
26                 protected override void Compile (Compiler c)
27                 {
28                         c.AssertAttribute ("test");
29                         test = c.CompileExpression (c.GetAttribute ("test"));
30
31                         if (!c.Input.MoveToFirstChild ()) return;
32                         children = c.CompileTemplateContent ();
33                         c.Input.MoveToParent ();
34                 }       
35                 
36                 public bool EvaluateIfTrue (XslTransformProcessor p)
37                 {
38                         if (p.EvaluateBoolean (test)) {
39                                 children.Evaluate (p);
40                                 return true;
41                         }
42                         return false;
43                 }
44
45                 public override void Evaluate (XslTransformProcessor p)
46                 {
47                         EvaluateIfTrue (p);
48                 }
49         }
50 }