Exemplo n.º 1
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                if (!fallback)
                {
                    throw XsltException.UnexpectedKeyword(this.name, this.parent);
                }
                if (this.containedActions != null && this.containedActions.Count > 0)
                {
                    processor.PushActionFrame(frame);
                    frame.State = ProcessingChildren;
                    break;
                }
                else
                {
                    goto case ProcessingChildren;
                }

            case ProcessingChildren:
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid Container action execution state");
                break;
            }
        }
Exemplo n.º 2
0
        private void CompileContent(Compiler compiler)
        {
            if (compiler.Recurse())
            {
                NavigatorInput input = compiler.Input;

                this.text = String.Empty;

                do
                {
                    switch (input.NodeType)
                    {
                    case XPathNodeType.Text:
                    case XPathNodeType.Whitespace:
                    case XPathNodeType.SignificantWhitespace:
                        this.text += input.Value;
                        break;

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

                    default:
                        throw XsltException.UnexpectedKeyword(compiler);
                    }
                } while(compiler.Advance());
                compiler.ToParent();
            }
        }
Exemplo n.º 3
0
        private void CompileConditions(Compiler compiler)
        {
            NavigatorInput input     = compiler.Input;
            bool           when      = false;
            bool           otherwise = false;

            do
            {
                Debug.Trace(input);

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

                    if (Keywords.Equals(nspace, input.Atoms.XsltNamespace))
                    {
                        IfAction action = null;
                        if (Keywords.Equals(name, input.Atoms.When) && !otherwise)
                        {
                            action = compiler.CreateIfAction(IfAction.ConditionType.ConditionWhen);
                            when   = true;
                        }
                        else if (Keywords.Equals(name, input.Atoms.Otherwise) && !otherwise)
                        {
                            action    = compiler.CreateIfAction(IfAction.ConditionType.ConditionOtherwise);
                            otherwise = true;
                        }
                        else
                        {
                            throw XsltException.UnexpectedKeyword(compiler);
                        }
                        AddAction(action);
                    }
                    else
                    {
                        throw XsltException.UnexpectedKeyword(compiler);
                    }
                    compiler.PopScope();
                    break;

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

                default:
                    throw new XsltException(Res.Xslt_InvalidContents, Keywords.s_Choose);
                }
            }while (compiler.Advance());
            if (!when)
            {
                throw new XsltException(Res.Xslt_NoWhen);
            }
        }
Exemplo n.º 4
0
        private void CompileContent(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            if (compiler.Recurse())
            {
                do
                {
                    Debug.Trace(input);

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

                        if (Keywords.Equals(nspace, input.Atoms.XsltNamespace))
                        {
                            if (Keywords.Equals(name, input.Atoms.Sort))
                            {
                                this.sort = true;
                                AddAction(compiler.CreateSortAction());
                            }
                            else if (Keywords.Equals(name, input.Atoms.WithParam))
                            {
                                WithParamAction par = compiler.CreateWithParamAction();
                                CheckDuplicateParams(par.Name);
                                AddAction(par);
                            }
                            else
                            {
                                throw XsltException.UnexpectedKeyword(compiler);
                            }
                        }
                        else
                        {
                            throw XsltException.UnexpectedKeyword(compiler);
                        }
                        compiler.PopScope();
                        break;

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

                    default:
                        throw new XsltException(Res.Xslt_InvalidContents, Keywords.s_ApplyTemplates);
                    }
                }while (compiler.Advance());

                compiler.ToParent();
            }
        }
Exemplo n.º 5
0
        private void CompileContent(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            if (compiler.Recurse())
            {
                do
                {
                    Debug.Trace(input);

                    switch (input.NodeType)
                    {
                    case XPathNodeType.Element:
                        compiler.PushNamespaceScope();

                        string nspace = input.NamespaceURI;
                        string name   = input.LocalName;

                        if (Keywords.Equals(nspace, input.Atoms.XsltNamespace) && Keywords.Equals(name, input.Atoms.Attribute))
                        {
                            // found attribute so add it
                            AddAction(compiler.CreateAttributeAction());
                        }
                        else
                        {
                            throw XsltException.UnexpectedKeyword(compiler);
                        }
                        compiler.PopScope();
                        break;

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

                    default:
                        throw new XsltException(Res.Xslt_InvalidContents, Keywords.s_AttributeSet);
                    }
                }while(compiler.Advance());

                compiler.ToParent();
            }
        }
Exemplo n.º 6
0
        void CompileInstruction(Compiler compiler)
        {
            NavigatorInput input  = compiler.Input;
            CompiledAction action = null;

            Debug.Assert(Keywords.Equals(input.NamespaceURI, input.Atoms.XsltNamespace));

            string name = input.LocalName;

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

            Debug.Assert(action != null);

            AddAction(action);
        }
Exemplo n.º 7
0
        protected void CompileTopLevelElements(Compiler compiler)
        {
            // Navigator positioned at parent root, need to move to child and then back
            if (compiler.Recurse() == false)
            {
                Debug.WriteLine("Nothing to compile, exiting");
                return;
            }

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

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

                    if (Keywords.Equals(nspace, input.Atoms.XsltNamespace))
                    {
                        if (Keywords.Equals(name, input.Atoms.Import))
                        {
                            if (notFirstElement)
                            {
                                throw new XsltException(Res.Xslt_NotFirstImport);
                            }
                            // We should compile imports in reverse order after all toplevel elements.
                            // remember it now and return to it in CompileImpoorts();
                            compiler.CompiledStylesheet.Imports.Add(compiler.GetSingleAttribute(compiler.Input.Atoms.Href));
                        }
                        else if (Keywords.Equals(name, input.Atoms.Include))
                        {
                            notFirstElement = true;
                            CompileInclude(compiler);
                        }
                        else
                        {
                            notFirstElement = true;
                            compiler.PushNamespaceScope();
                            if (Keywords.Equals(name, input.Atoms.StripSpace))
                            {
                                CompileSpace(compiler, false);
                            }
                            else if (Keywords.Equals(name, input.Atoms.PreserveSpace))
                            {
                                CompileSpace(compiler, true);
                            }
                            else if (Keywords.Equals(name, input.Atoms.Output))
                            {
                                CompileOutput(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.Key))
                            {
                                CompileKey(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.DecimalFormat))
                            {
                                CompileDecimalFormat(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.NamespaceAlias))
                            {
                                CompileNamespaceAlias(compiler);
                            }
                            else if (Keywords.Equals(name, input.Atoms.AttributeSet))
                            {
                                compiler.AddAttributeSet(compiler.CreateAttributeSetAction());
                            }
                            else if (Keywords.Equals(name, input.Atoms.Variable))
                            {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalVariable);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Keywords.Equals(name, input.Atoms.Param))
                            {
                                VariableAction action = compiler.CreateVariableAction(VariableType.GlobalParameter);
                                if (action != null)
                                {
                                    AddAction(action);
                                }
                            }
                            else if (Keywords.Equals(name, input.Atoms.Template))
                            {
                                compiler.AddTemplate(compiler.CreateTemplateAction());
                            }
                            else
                            {
                                if (!compiler.ForwardCompatibility)
                                {
                                    throw XsltException.UnexpectedKeyword(compiler);
                                }
                            }
                            compiler.PopScope();
                        }
                    }
                    else if (nspace == input.Atoms.MsXsltNamespace && name == input.Atoms.Script)
                    {
                        AddScript(compiler);
                    }
                    else
                    {
                        if (Keywords.Equals(nspace, input.Atoms.Empty))
                        {
                            throw new XsltException(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 new XsltException(Res.Xslt_InvalidContents, "xsl:stylesheet");
                }
            }while (compiler.Advance());

            compiler.ToParent();
        }