ToParent() private method

private ToParent ( ) : bool
return bool
Ejemplo n.º 1
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, _nameAvt, "name");

            _name  = PrecalculateAvt(ref _nameAvt);
            _nsUri = PrecalculateAvt(ref _nsAvt);

            // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
            if (_nameAvt == null && _nsAvt == null)
            {
                if (_name != "xmlns")
                {
                    _qname = CreateElementQName(_name, _nsUri, compiler.CloneScopeManager());
                }
            }
            else
            {
                _manager = compiler.CloneScopeManager();
            }

            if (compiler.Recurse())
            {
                Debug.Assert(_empty == false);
                CompileTemplate(compiler);
                compiler.ToParent();
            }
            _empty = (this.containedActions == null);
        }
Ejemplo n.º 2
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.nameAvt, "name");

            this.name  = PrecalculateAvt(ref this.nameAvt);
            this.nsUri = PrecalculateAvt(ref this.nsAvt);

            // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
            if (this.nameAvt == null && this.nsAvt == null)
            {
                if (this.name != "xmlns")
                {
                    this.qname = CreateAttributeQName(this.name, this.nsUri, compiler.CloneScopeManager());
                }
            }
            else
            {
                this.manager = compiler.CloneScopeManager();
            }

            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
        private void CompileContent(Compiler compiler) {
            NavigatorInput input = compiler.Input;
            
            if (compiler.Recurse()) {
                do {
                    switch(input.NodeType) {
                    case XPathNodeType.Element:
                        compiler.PushNamespaceScope();
                        string nspace = input.NamespaceURI;
                        string name   = input.LocalName;

                        if (Ref.Equal(nspace, input.Atoms.UriXsl) && Ref.Equal(name, input.Atoms.WithParam)) {
                                WithParamAction par = compiler.CreateWithParamAction();
                                CheckDuplicateParams(par.Name);
                                AddAction(par);
                        }
                        else {
                            throw compiler.UnexpectedKeyword();
                        }
                        compiler.PopScope();
                        break;
                    case XPathNodeType.Comment:
                    case XPathNodeType.ProcessingInstruction:
                    case XPathNodeType.Whitespace:
                    case XPathNodeType.SignificantWhitespace:
                        break;
                    default:
                        throw XsltException.Create(Res.Xslt_InvalidContents, "call-template");
                    }
                } while(compiler.Advance());

                compiler.ToParent();
            }
        }
Ejemplo n.º 4
0
        private void CompileContent(Compiler compiler)
        {
            if (compiler.Recurse())
            {
                NavigatorInput input = compiler.Input;

                _text = string.Empty;

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

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

                    default:
                        throw compiler.UnexpectedKeyword();
                    }
                } while (compiler.Advance());
                compiler.ToParent();
            }
        }
Ejemplo n.º 5
0
        private void CompileLiteral(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            switch (input.NodeType)
            {
            case XPathNodeType.Element:
                this.AddEvent(compiler.CreateBeginEvent());
                CompileLiteralAttributesAndNamespaces(compiler);

                if (compiler.Recurse())
                {
                    CompileTemplate(compiler);
                    compiler.ToParent();
                }

                this.AddEvent(new EndEvent(XPathNodeType.Element));
                break;

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

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

            default:
                Debug.Fail("Unexpected node type.");
                break;
            }
        }
Ejemplo n.º 6
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            if (_matchKey == Compiler.InvalidQueryKey)
            {
                if (_name == null)
                {
                    throw XsltException.Create(SR.Xslt_TemplateNoAttrib);
                }
                if (_mode != null)
                {
                    throw XsltException.Create(SR.Xslt_InvalidModeAttribute);
                }
            }
            compiler.BeginTemplate(this);

            if (compiler.Recurse())
            {
                CompileParameters(compiler);
                CompileTemplate(compiler);

                compiler.ToParent();
            }

            compiler.EndTemplate();
            AnalyzePriority(compiler);
        }
Ejemplo n.º 7
0
        internal override void Compile(Compiler compiler)
        {
            this.stylesheetid = compiler.Stylesheetid;
            this.baseUri = compiler.Input.BaseURI;
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.name, "name");


            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();

                if (this.selectKey != Compiler.InvalidQueryKey && this.containedActions != null)
                {
                    throw XsltException.Create(SR.Xslt_VariableCntSel2, this.nameStr);
                }
            }
            if (this.containedActions != null)
            {
                baseUri = baseUri + '#' + compiler.GetUnicRtfId();
            }
            else
            {
                baseUri = null;
            }

            _varKey = compiler.InsertVariable(this);
        }
Ejemplo n.º 8
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name);

            this.name  = PrecalculateAvt(ref this.nameAvt);
            this.nsUri = PrecalculateAvt(ref this.nsAvt);

            // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
            if (this.nameAvt == null && this.nsAvt == null)
            {
                if (this.name != Keywords.s_Xmlns)
                {
                    this.qname = CreateElementQName(this.name, this.nsUri, compiler.CloneScopeManager());
                }
            }
            else
            {
                this.manager = compiler.CloneScopeManager();
            }

            if (compiler.Recurse())
            {
                Debug.Assert(this.empty == false);
                CompileTemplate(compiler);
                compiler.ToParent();
            }
            this.empty = (this.containedActions == null);
        }
Ejemplo n.º 9
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            if (_matchKey == Compiler.InvalidQueryKey)
            {
                if (_name == null)
                {
                    throw XsltException.Create(SR.Xslt_TemplateNoAttrib);
                }
                if (_mode != null)
                {
                    throw XsltException.Create(SR.Xslt_InvalidModeAttribute);
                }
            }
            compiler.BeginTemplate(this);

            if (compiler.Recurse())
            {
                CompileParameters(compiler);
                CompileTemplate(compiler);

                compiler.ToParent();
            }

            compiler.EndTemplate();
            AnalyzePriority(compiler);
        }
Ejemplo n.º 10
0
        private void CompileContent(Compiler compiler)
        {
            if (compiler.Recurse())
            {
                NavigatorInput input = compiler.Input;

                _text = string.Empty;

                do
                {
                    switch (input.NodeType)
                    {
                        case XPathNodeType.Text:
                        case XPathNodeType.Whitespace:
                        case XPathNodeType.SignificantWhitespace:
                            _text += input.Value;
                            break;
                        case XPathNodeType.Comment:
                        case XPathNodeType.ProcessingInstruction:
                            break;
                        default:
                            throw compiler.UnexpectedKeyword();
                    }
                } while (compiler.Advance());
                compiler.ToParent();
            }
        }
        internal override void Compile(Compiler compiler)
        {
            this.stylesheetid = compiler.Stylesheetid;
            this.baseUri      = compiler.Input.BaseURI;
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.name, "name");


            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();

                if (this.selectKey != Compiler.InvalidQueryKey && this.containedActions != null)
                {
                    throw XsltException.Create(SR.Xslt_VariableCntSel2, this.nameStr);
                }
            }
            if (this.containedActions != null)
            {
                baseUri = baseUri + '#' + compiler.GetUnicRtfId();
            }
            else
            {
                baseUri = null;
            }

            _varKey = compiler.InsertVariable(this);
        }
Ejemplo n.º 12
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, _nameAvt, "name");

            _name = PrecalculateAvt(ref _nameAvt);
            _nsUri = PrecalculateAvt(ref _nsAvt);

            // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
            if (_nameAvt == null && _nsAvt == null)
            {
                if (_name != "xmlns")
                {
                    _qname = CreateElementQName(_name, _nsUri, compiler.CloneScopeManager());
                }
            }
            else
            {
                _manager = compiler.CloneScopeManager();
            }

            if (compiler.Recurse())
            {
                Debug.Assert(_empty == false);
                CompileTemplate(compiler);
                compiler.ToParent();
            }
            _empty = (this.containedActions == null);
        }
Ejemplo n.º 13
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);

            if (compiler.Recurse()) {
                CompileConditions(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 14
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);

            if (compiler.Recurse()) {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);

            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 16
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);

            if (compiler.Recurse())
            {
                CompileConditions(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 17
0
 internal override void Compile(Compiler compiler) {
     XPathNavigator nav = compiler.Input.Navigator.Clone();
     name = nav.Name;
     nav.MoveToParent();
     parent = nav.Name;
     if (compiler.Recurse()) {
         CompileSelectiveTemplate(compiler);
         compiler.ToParent();
     }
 }
Ejemplo n.º 18
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            if (this.type != ConditionType.ConditionOtherwise) {
                CheckRequiredAttribute(compiler, this.testKey != Compiler.InvalidQueryKey, "test");
            }

            if (compiler.Recurse()) {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 19
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);

            if (compiler.Recurse()) {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
            if (this.containedActions == null)
                this.empty = true;
                
        }
Ejemplo n.º 20
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, selectKey != Compiler.InvalidQueryKey, Keywords.s_Select);

            compiler.CanHaveApplyImports = false;
            if (compiler.Recurse()) {
                CompileSortElements(compiler);
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 21
0
        private void CompileContent(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

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

                        if (Ref.Equal(nspace, input.Atoms.UriXsl))
                        {
                            if (Ref.Equal(name, input.Atoms.Sort))
                            {
                                AddAction(compiler.CreateSortAction());
                            }
                            else if (Ref.Equal(name, input.Atoms.WithParam))
                            {
                                WithParamAction par = compiler.CreateWithParamAction();
                                CheckDuplicateParams(par.Name);
                                AddAction(par);
                            }
                            else
                            {
                                throw compiler.UnexpectedKeyword();
                            }
                        }
                        else
                        {
                            throw compiler.UnexpectedKeyword();
                        }
                        compiler.PopScope();
                        break;

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

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

                compiler.ToParent();
            }
        }
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.name, Keywords.s_Name);
            if (compiler.Recurse()) {
                CompileTemplate(compiler);
                compiler.ToParent();

                if (this.selectKey != Compiler.InvalidQueryKey && this.containedActions != null) {
                    throw XsltException.Create(Res.Xslt_VariableCntSel2, this.nameStr);
                }
            }
        }
Ejemplo n.º 23
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, selectKey != Compiler.InvalidQueryKey, "select");

            compiler.CanHaveApplyImports = false;
            if (compiler.Recurse())
            {
                CompileSortElements(compiler);
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 24
0
        internal override void Compile(Compiler compiler)
        {
            XPathNavigator nav = compiler.Input.Navigator.Clone();

            name = nav.Name;
            nav.MoveToParent();
            parent = nav.Name;
            if (compiler.Recurse())
            {
                CompileSelectiveTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 25
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            if (_type != ConditionType.ConditionOtherwise)
            {
                CheckRequiredAttribute(compiler, _testKey != Compiler.InvalidQueryKey, "test");
            }

            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 26
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);

            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
            if (this.containedActions == null)
            {
                this.empty = true;
            }
        }
Ejemplo n.º 27
0
 internal void CompileSelectiveTemplate(Compiler compiler){
     NavigatorInput input = compiler.Input;
     do{
         if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl) &&
             Ref.Equal(input.LocalName, input.Atoms.Fallback)){
             fallback = true;
             if (compiler.Recurse()){
                 CompileTemplate(compiler);
                 compiler.ToParent();
             }
         }
     }
     while (compiler.Advance());
 }
Ejemplo n.º 28
0
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.name, "name");
            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();

                if (this.selectKey != Compiler.InvalidQueryKey && this.containedActions != null)
                {
                    throw XsltException.Create(SR.Xslt_VariableCntSel2, this.nameStr);
                }
            }
        }
Ejemplo n.º 29
0
        internal void CompileSelectiveTemplate(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            do
            {
                if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl) &&
                    Ref.Equal(input.LocalName, input.Atoms.Fallback))
                {
                    fallback = true;
                    if (compiler.Recurse())
                    {
                        CompileTemplate(compiler);
                        compiler.ToParent();
                    }
                }
            }while (compiler.Advance());
        }
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name);

            if(this.nameAvt.IsConstant) {
                this.name    = this.nameAvt.Evaluate(null, null);
                this.nameAvt = null;
                if (! IsProcessingInstructionName(this.name)) {
                    // For Now: set to null to ignore action late;
                   this.name = null;
               }
            }

            if (compiler.Recurse()) {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 31
0
 public void CheckEmpty(Compiler compiler) {
     // Really EMPTY means no content at all, but the sake of compatibility with MSXML we allow whitespaces
     string elementName = compiler.Input.Name;
     if (compiler.Recurse()) {
         do {
             // Note: <![CDATA[ ]]> will be reported as XPathNodeType.Text
             XPathNodeType nodeType = compiler.Input.NodeType;
             if (
                 nodeType != XPathNodeType.Whitespace            &&
                 nodeType != XPathNodeType.Comment               &&
                 nodeType != XPathNodeType.ProcessingInstruction
             ) {
                 throw XsltException.Create(Res.Xslt_NotEmptyContents, elementName);
             }
         }
         while (compiler.Advance());
         compiler.ToParent();
     }
 }
        private void CompileContent(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            if (compiler.Recurse())
            {
                do
                {
                    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 compiler.UnexpectedKeyword();
                        }
                        compiler.PopScope();
                        break;

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

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

                compiler.ToParent();
            }
        }
Ejemplo n.º 33
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.nameAvt, "name");

            this.name  = PrecalculateAvt(ref this.nameAvt);
            this.nsUri = PrecalculateAvt(ref this.nsAvt  );

            // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
            if (this.nameAvt == null && this.nsAvt == null) {
                if(this.name != "xmlns") {
                    this.qname = CreateAttributeQName(this.name, this.nsUri, compiler.CloneScopeManager());                    
                }
            }
            else {
                this.manager = compiler.CloneScopeManager();
            }

            if (compiler.Recurse()) {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
        internal override void Compile(Compiler compiler)
        {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, _nameAvt, "name");

            if (_nameAvt.IsConstant)
            {
                _name    = _nameAvt.Evaluate(null, null);
                _nameAvt = null;
                if (!IsProcessingInstructionName(_name))
                {
                    // For Now: set to null to ignore action late;
                    _name = null;
                }
            }

            if (compiler.Recurse())
            {
                CompileTemplate(compiler);
                compiler.ToParent();
            }
        }
Ejemplo n.º 35
0
        public void CheckEmpty(Compiler compiler)
        {
            // Really EMPTY means no content at all, but the sake of compatibility with MSXML we allow whitespaces
            string elementName = compiler.Input.Name;

            if (compiler.Recurse())
            {
                do
                {
                    // Note: <![CDATA[ ]]> will be reported as XPathNodeType.Text
                    XPathNodeType nodeType = compiler.Input.NodeType;
                    if (
                        nodeType != XPathNodeType.Whitespace &&
                        nodeType != XPathNodeType.Comment &&
                        nodeType != XPathNodeType.ProcessingInstruction
                        )
                    {
                        throw XsltException.Create(Res.Xslt_NotEmptyContents, elementName);
                    }
                }while (compiler.Advance());
                compiler.ToParent();
            }
        }
        private void CompileContent(Compiler compiler) {
            NavigatorInput input = compiler.Input;

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

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

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

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

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

                compiler.ToParent();
            }
        }
Ejemplo n.º 37
0
        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name);

            this.name  = PrecalculateAvt(ref this.nameAvt);
            this.nsUri = PrecalculateAvt(ref this.nsAvt  );

            // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore
            if (this.nameAvt == null && this.nsAvt == null) {
                if(this.name != Keywords.s_Xmlns) {
                    this.qname = CreateElementQName(this.name, this.nsUri, compiler.CloneScopeManager());                    
                }
            }
            else {
                this.manager = compiler.CloneScopeManager();
            }

            if (compiler.Recurse()) {
                Debug.Assert(this.empty == false);
                CompileTemplate(compiler);
                compiler.ToParent();
            }
            this.empty = (this.containedActions == null) ;
        }
Ejemplo n.º 38
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();
        }
        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();
        }
        void CompileLiteral(Compiler compiler) {
            NavigatorInput input = compiler.Input;

            switch (input.NodeType) {
            case XPathNodeType.Element:
                this.AddEvent(compiler.CreateBeginEvent());
                CompileLiteralAttributesAndNamespaces(compiler);

                if (compiler.Recurse()) {
                    CompileTemplate(compiler);
                    compiler.ToParent();
                }

                this.AddEvent(new EndEvent(XPathNodeType.Element));
                break;

            case XPathNodeType.Text:
            case XPathNodeType.SignificantWhitespace:
                this.AddEvent(compiler.CreateTextEvent());
                break;
            case XPathNodeType.Whitespace:
            case XPathNodeType.ProcessingInstruction:
            case XPathNodeType.Comment:
                break;

            default:
                Debug.Assert(false, "Unexpected node type.");
                break;
            }
        }