CreateVariableAction() public method

public CreateVariableAction ( VariableType type ) : VariableAction
type VariableType
return VariableAction
Ejemplo n.º 1
0
        protected void CompileParameters(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            do
            {
                switch (input.NodeType)
                {
                case XPathNodeType.Element:
                    if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl) &&
                        Ref.Equal(input.LocalName, input.Atoms.Param))
                    {
                        compiler.PushNamespaceScope();
                        AddAction(compiler.CreateVariableAction(VariableType.LocalParameter));
                        compiler.PopScope();
                        continue;
                    }
                    else
                    {
                        return;
                    }

                case XPathNodeType.Text:
                    return;

                case XPathNodeType.SignificantWhitespace:
                    this.AddEvent(compiler.CreateTextEvent());
                    continue;

                default:
                    continue;
                }
            }while (input.Advance());
        }
Ejemplo n.º 2
0
        private void CompileInstruction(Compiler compiler)
        {
            NavigatorInput input  = compiler.Input;
            CompiledAction?action = null;

            Debug.Assert(Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl));

            string name = input.LocalName;

            if (Ref.Equal(name, input.Atoms.ApplyImports))
            {
                action = compiler.CreateApplyImportsAction();
            }
            else if (Ref.Equal(name, input.Atoms.ApplyTemplates))
            {
                action = compiler.CreateApplyTemplatesAction();
            }
            else if (Ref.Equal(name, input.Atoms.Attribute))
            {
                action = compiler.CreateAttributeAction();
            }
            else if (Ref.Equal(name, input.Atoms.CallTemplate))
            {
                action = compiler.CreateCallTemplateAction();
            }
            else if (Ref.Equal(name, input.Atoms.Choose))
            {
                action = compiler.CreateChooseAction();
            }
            else if (Ref.Equal(name, input.Atoms.Comment))
            {
                action = compiler.CreateCommentAction();
            }
            else if (Ref.Equal(name, input.Atoms.Copy))
            {
                action = compiler.CreateCopyAction();
            }
            else if (Ref.Equal(name, input.Atoms.CopyOf))
            {
                action = compiler.CreateCopyOfAction();
            }
            else if (Ref.Equal(name, input.Atoms.Element))
            {
                action = compiler.CreateElementAction();
            }
            else if (Ref.Equal(name, input.Atoms.Fallback))
            {
                return;
            }
            else if (Ref.Equal(name, input.Atoms.ForEach))
            {
                action = compiler.CreateForEachAction();
            }
            else if (Ref.Equal(name, input.Atoms.If))
            {
                action = compiler.CreateIfAction(IfAction.ConditionType.ConditionIf);
            }
            else if (Ref.Equal(name, input.Atoms.Message))
            {
                action = compiler.CreateMessageAction();
            }
            else if (Ref.Equal(name, input.Atoms.Number))
            {
                action = compiler.CreateNumberAction();
            }
            else if (Ref.Equal(name, input.Atoms.ProcessingInstruction))
            {
                action = compiler.CreateProcessingInstructionAction();
            }
            else if (Ref.Equal(name, input.Atoms.Text))
            {
                action = compiler.CreateTextAction();
            }
            else if (Ref.Equal(name, input.Atoms.ValueOf))
            {
                action = compiler.CreateValueOfAction();
            }
            else if (Ref.Equal(name, input.Atoms.Variable))
            {
                action = compiler.CreateVariableAction(VariableType.LocalVariable);
            }
            else
            {
                if (compiler.ForwardCompatibility)
                {
                    action = compiler.CreateNewInstructionAction();
                }
                else
                {
                    throw compiler.UnexpectedKeyword();
                }
            }

            Debug.Assert(action != null);

            AddAction(action);
        }
Ejemplo n.º 3
0
        // SxS: This method does not take any resource name and does not expose any resources to the caller.
        // It's OK to suppress the SxS warning.
        protected void CompileTopLevelElements(Compiler compiler)
        {
            // Navigator positioned at parent root, need to move to child and then back
            if (compiler.Recurse() == false)
            {
                return;
            }

            NavigatorInput input           = compiler.Input;
            bool           notFirstElement = false;

            do
            {
                switch (input.NodeType)
                {
                case XPathNodeType.Element:
                    string name   = input.LocalName;
                    string nspace = input.NamespaceURI;

                    if (Ref.Equal(nspace, input.Atoms.UriXsl))
                    {
                        if (Ref.Equal(name, input.Atoms.Import))
                        {
                            if (notFirstElement)
                            {
                                throw XsltException.Create(SR.Xslt_NotFirstImport);
                            }
                            // We should compile imports in reverse order after all toplevel elements.
                            // remember it now and return to it in CompileImpoorts();
                            Uri    uri      = compiler.ResolveUri(compiler.GetSingleAttribute(compiler.Input.Atoms.Href));
                            string resolved = uri.ToString();
                            if (compiler.IsCircularReference(resolved))
                            {
                                throw XsltException.Create(SR.Xslt_CircularInclude, resolved);
                            }
                            compiler.CompiledStylesheet !.Imports.Add(uri);
                            CheckEmpty(compiler);
                        }
                        else if (Ref.Equal(name, input.Atoms.Include))
                        {
                            notFirstElement = true;
                            CompileInclude(compiler);
                        }
                        else
                        {
                            notFirstElement = true;
                            compiler.PushNamespaceScope();
                            if (Ref.Equal(name, input.Atoms.StripSpace))
                            {
                                CompileSpace(compiler, false);
                            }
                            else if (Ref.Equal(name, input.Atoms.PreserveSpace))
                            {
                                CompileSpace(compiler, true);
                            }
                            else if (Ref.Equal(name, input.Atoms.Output))
                            {
                                CompileOutput(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.Key))
                            {
                                CompileKey(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.DecimalFormat))
                            {
                                CompileDecimalFormat(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.NamespaceAlias))
                            {
                                CompileNamespaceAlias(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.AttributeSet))
                            {
                                compiler.AddAttributeSet(compiler.CreateAttributeSetAction());
                            }
                            else if (Ref.Equal(name, input.Atoms.Variable))
                            {
                                VariableAction?action = compiler.CreateVariableAction(VariableType.GlobalVariable);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Ref.Equal(name, input.Atoms.Param))
                            {
                                VariableAction?action = compiler.CreateVariableAction(VariableType.GlobalParameter);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Ref.Equal(name, input.Atoms.Template))
                            {
                                compiler.AddTemplate(compiler.CreateTemplateAction());
                            }
                            else
                            {
                                if (!compiler.ForwardCompatibility)
                                {
                                    throw compiler.UnexpectedKeyword();
                                }
                            }
                            compiler.PopScope();
                        }
                    }
                    else if (nspace == input.Atoms.UrnMsxsl && name == input.Atoms.Script)
                    {
                        AddScript(compiler);
                    }
                    else
                    {
                        if (nspace.Length == 0)
                        {
                            throw XsltException.Create(SR.Xslt_NullNsAtTopLevel, input.Name);
                        }
                        // Ignoring non-recognized namespace per XSLT spec 2.2
                    }
                    break;

                case XPathNodeType.ProcessingInstruction:
                case XPathNodeType.Comment:
                case XPathNodeType.Whitespace:
                case XPathNodeType.SignificantWhitespace:
                    break;

                default:
                    throw XsltException.Create(SR.Xslt_InvalidContents, "stylesheet");
                }
            }while (compiler.Advance());

            compiler.ToParent();
        }
        void CompileInstruction(Compiler compiler) {
            NavigatorInput input  = compiler.Input;
            CompiledAction action = null;

            Debug.Assert(Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl));

            string name = input.LocalName;

            if (Ref.Equal(name, input.Atoms.ApplyImports)) {
                action = compiler.CreateApplyImportsAction();
            }
            else if (Ref.Equal(name, input.Atoms.ApplyTemplates)) {
                action = compiler.CreateApplyTemplatesAction();
            }
            else if (Ref.Equal(name, input.Atoms.Attribute)) {
                action = compiler.CreateAttributeAction();
            }
            else if (Ref.Equal(name, input.Atoms.CallTemplate)) {
                action = compiler.CreateCallTemplateAction();
            }
            else if (Ref.Equal(name, input.Atoms.Choose)) {
                action = compiler.CreateChooseAction();
            }
            else if (Ref.Equal(name, input.Atoms.Comment)) {
                action = compiler.CreateCommentAction();
            }
            else if (Ref.Equal(name, input.Atoms.Copy)) {
                action = compiler.CreateCopyAction();
            }
            else if (Ref.Equal(name, input.Atoms.CopyOf)) {
                action = compiler.CreateCopyOfAction();
            }
            else if (Ref.Equal(name, input.Atoms.Element)) {
                action = compiler.CreateElementAction();
            }
            else if (Ref.Equal(name, input.Atoms.Fallback)) {
                return;
            }
            else if (Ref.Equal(name, input.Atoms.ForEach)) {
                action = compiler.CreateForEachAction();
            }
            else if (Ref.Equal(name, input.Atoms.If)) {
                action = compiler.CreateIfAction(IfAction.ConditionType.ConditionIf);
            }
            else if (Ref.Equal(name, input.Atoms.Message)) {
                action = compiler.CreateMessageAction();
            }
            else if (Ref.Equal(name, input.Atoms.Number)) {
                action = compiler.CreateNumberAction();
            }
            else if (Ref.Equal(name, input.Atoms.ProcessingInstruction)) {
                action = compiler.CreateProcessingInstructionAction();
            }
            else if (Ref.Equal(name, input.Atoms.Text)) {
                action = compiler.CreateTextAction();
            }
            else if (Ref.Equal(name, input.Atoms.ValueOf)) {
                action = compiler.CreateValueOfAction();
            }
            else if (Ref.Equal(name, input.Atoms.Variable)) {
                action = compiler.CreateVariableAction(VariableType.LocalVariable);
            }
            else {
                if (compiler.ForwardCompatibility)
                    action = compiler.CreateNewInstructionAction();
                else
                    throw compiler.UnexpectedKeyword();
            }

            Debug.Assert(action != null);

            AddAction(action);
        }
        protected void CompileTopLevelElements(Compiler compiler) {
            // Navigator positioned at parent root, need to move to child and then back
            if (compiler.Recurse() == false) {
                return;
            }

            NavigatorInput input    = compiler.Input;
            bool notFirstElement    = false;
            do {
                switch (input.NodeType) {
                case XPathNodeType.Element:
                    string name   = input.LocalName;
                    string nspace = input.NamespaceURI;

                    if (Ref.Equal(nspace, input.Atoms.UriXsl)) {
                        if (Ref.Equal(name, input.Atoms.Import)) {
                            if (notFirstElement) {
                                throw XsltException.Create(Res.Xslt_NotFirstImport);
                            }
                            // We should compile imports in reverse order after all toplevel elements.
                            // remember it now and return to it in CompileImpoorts();
                            Uri uri = compiler.ResolveUri(compiler.GetSingleAttribute(compiler.Input.Atoms.Href));
                            string resolved = uri.ToString();
                            if (compiler.IsCircularReference(resolved)) {
                                throw XsltException.Create(Res.Xslt_CircularInclude, resolved);
                            }
                            compiler.CompiledStylesheet.Imports.Add(uri);
                            CheckEmpty(compiler);
                        }
                        else if (Ref.Equal(name, input.Atoms.Include)) {
                            notFirstElement = true;
                            CompileInclude(compiler);
                        }
                        else {
                            notFirstElement = true;
                            compiler.PushNamespaceScope();
                            if (Ref.Equal(name, input.Atoms.StripSpace)) {
                                CompileSpace(compiler, false);
                            }
                            else if (Ref.Equal(name, input.Atoms.PreserveSpace)) {
                                CompileSpace(compiler, true);
                            }
                            else if (Ref.Equal(name, input.Atoms.Output)) {
                                CompileOutput(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.Key)) {
                                CompileKey(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.DecimalFormat)) {
                                CompileDecimalFormat(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.NamespaceAlias)) {
                                CompileNamespaceAlias(compiler);
                            }
                            else if (Ref.Equal(name, input.Atoms.AttributeSet)) {
                                compiler.AddAttributeSet(compiler.CreateAttributeSetAction());
                            }
                            else if (Ref.Equal(name, input.Atoms.Variable)) {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalVariable);
                                if (action != null) {
                                    AddAction(action);
                                }
                            }
                            else if (Ref.Equal(name, input.Atoms.Param)) {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalParameter);
                                if (action != null) {
                                    AddAction(action);
                                }
                            }
                            else if (Ref.Equal(name, input.Atoms.Template)) {
                                compiler.AddTemplate(compiler.CreateTemplateAction());
                            }
                            else {
                                if (!compiler.ForwardCompatibility) {
                                    throw compiler.UnexpectedKeyword();
                                }
                            }
                            compiler.PopScope();
                        }
                    }
#if !DISABLE_XSLT_SCRIPT
                    else if (nspace == input.Atoms.UrnMsxsl && name == input.Atoms.Script) {
                        AddScript(compiler);
                    }
#endif
                    else {
                        if (nspace.Length == 0) {
                            throw XsltException.Create(Res.Xslt_NullNsAtTopLevel, input.Name);
                        }
                        // Ignoring non-recognized namespace per XSLT spec 2.2
                    }
                    break;

                case XPathNodeType.ProcessingInstruction:
                case XPathNodeType.Comment:
                case XPathNodeType.Whitespace:
                case XPathNodeType.SignificantWhitespace:
                    break;

                default:
                    throw XsltException.Create(Res.Xslt_InvalidContents, "stylesheet");
                }
            }
            while (compiler.Advance());

            compiler.ToParent();
        }
 protected void CompileParameters(Compiler compiler) {
     NavigatorInput input = compiler.Input;
     do {
         switch(input.NodeType) {
         case XPathNodeType.Element:
             if (Keywords.Equals(input.NamespaceURI, input.Atoms.XsltNamespace) &&
                 Keywords.Equals(input.LocalName, input.Atoms.Param)) {
                 compiler.PushNamespaceScope();
                 AddAction(compiler.CreateVariableAction(VariableType.LocalParameter));
                 compiler.PopScope();
                 continue;
             }
             else {
                 return;
             }
         case XPathNodeType.Text:
             return;
         case XPathNodeType.SignificantWhitespace:
             this.AddEvent(compiler.CreateTextEvent());
             continue;
         default :
             continue;
         }
     }
     while (input.Advance());
 }