1 //------------------------------------------------------------------------------
2 // <copyright file="IfAction.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System.Xml.Xsl.XsltOld {
9 using Res = System.Xml.Utils.Res;
11 using System.Diagnostics;
13 using System.Xml.XPath;
15 internal class IfAction : ContainerAction {
16 internal enum ConditionType {
22 private ConditionType type;
23 private int testKey = Compiler.InvalidQueryKey;
25 internal IfAction(ConditionType type) {
29 internal override void Compile(Compiler compiler) {
30 CompileAttributes(compiler);
31 if (this.type != ConditionType.ConditionOtherwise) {
32 CheckRequiredAttribute(compiler, this.testKey != Compiler.InvalidQueryKey, "test");
35 if (compiler.Recurse()) {
36 CompileTemplate(compiler);
41 internal override bool CompileAttribute(Compiler compiler) {
42 string name = compiler.Input.LocalName;
43 string value = compiler.Input.Value;
44 if (Ref.Equal(name, compiler.Atoms.Test)) {
45 if (this.type == ConditionType.ConditionOtherwise) {
48 this.testKey = compiler.AddBooleanQuery(value);
57 internal override void Execute(Processor processor, ActionFrame frame) {
58 Debug.Assert(processor != null && frame != null);
60 switch (frame.State) {
62 if (this.type == ConditionType.ConditionIf || this.type == ConditionType.ConditionWhen) {
63 Debug.Assert(this.testKey != Compiler.InvalidQueryKey);
64 bool value = processor.EvaluateBoolean(frame, this.testKey);
71 processor.PushActionFrame(frame);
72 frame.State = ProcessingChildren;
73 break; // Allow children to run
75 case ProcessingChildren:
76 if (this.type == ConditionType.ConditionWhen ||this.type == ConditionType.ConditionOtherwise) {
77 Debug.Assert(frame.Container != null);
85 Debug.Fail("Invalid IfAction execution state");