Ejemplo n.º 1
0
        protected void CompileSortElements(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.Sort))
                    {
                        if (sortContainer == null)
                        {
                            sortContainer = new ContainerAction();
                        }
                        sortContainer.AddAction(compiler.CreateSortAction());
                        continue;
                    }
                    return;

                case XPathNodeType.Text:
                    return;

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

                default:
                    continue;
                }
            }while (input.Advance());
        }
Ejemplo n.º 2
0
        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());
        }
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Select))
            {
                this.select    = value;
                this.selectKey = compiler.AddQuery(this.select);
                Debug.WriteLine("apply-templates select: \"" + this.select + "\" (#" + this.selectKey.ToString() + ")");
            }
            else if (Keywords.Equals(name, compiler.Atoms.Mode))
            {
                Debug.Assert(this.mode == null);
                if (compiler.AllowBuiltInMode && value.Trim() == "*")
                {
                    this.mode = Compiler.BuiltInMode;
                }
                else
                {
                    this.mode = compiler.CreateXPathQName(value);
                }
                Debug.WriteLine("mode attribute found: \"" + this.mode + "\"");
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        private int FindAttribute(string name, string nspace, ref string prefix)
        {
            Debug.Assert(this.attributeCount <= this.attributeList.Count);

            for (int attrib = 0; attrib < this.attributeCount; attrib++)
            {
                Debug.Assert(this.attributeList[attrib] != null && this.attributeList[attrib] is BuilderInfo);

                BuilderInfo attribute = (BuilderInfo)this.attributeList[attrib];

                if (Keywords.Equals(attribute.LocalName, name))
                {
                    if (Keywords.Equals(attribute.NamespaceURI, nspace))
                    {
                        return(attrib);
                    }
                    if (Keywords.Equals(attribute.Prefix, prefix))
                    {
                        // prefix conflict. Should be renamed.
                        prefix = string.Empty;
                    }
                }
            }

            return(-1);
        }
Ejemplo n.º 5
0
        internal bool FindPrefix(string nspace, out string prefix)
        {
            Debug.Assert(nspace != null);
            for (int i = this.elementScopesStack.Length - 1; 0 <= i; i--)
            {
                Debug.Assert(this.elementScopesStack[i] is OutputScope);

                OutputScope elementScope = (OutputScope)this.elementScopesStack[i];
                string      pfx          = null;
                if (elementScope.FindPrefix(nspace, out pfx))
                {
                    string testNspace = ResolveNamespace(pfx);
                    if (testNspace != null && Keywords.Equals(testNspace, nspace))
                    {
                        prefix = pfx;
                        return(true);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            prefix = null;
            return(false);
        }
Ejemplo n.º 6
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Select))
            {
                this.selectKey = compiler.AddQuery(value);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Lang))
            {
                this.langAvt = Avt.CompileAvt(compiler, value);
            }
            else if (Keywords.Equals(name, compiler.Atoms.DataType))
            {
                this.dataTypeAvt = Avt.CompileAvt(compiler, value);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Order))
            {
                this.orderAvt = Avt.CompileAvt(compiler, value);
            }
            else if (Keywords.Equals(name, compiler.Atoms.CaseOrder))
            {
                this.caseOrderAvt = Avt.CompileAvt(compiler, value);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
        protected void CompileOnceTemplate(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            Debug.Trace(input);
            if (input.NodeType == XPathNodeType.Element)
            {
                string nspace = input.NamespaceURI;

                if (Keywords.Equals(nspace, input.Atoms.XsltNamespace))
                {
                    compiler.PushNamespaceScope();
                    CompileInstruction(compiler);
                    compiler.PopScope();
                }
                else
                {
                    compiler.PushLiteralScope();
                    compiler.InsertExtensionNamespace();
                    if (compiler.IsExtensionNamespace(nspace))
                    {
                        AddAction(compiler.CreateNewInstructionAction());
                    }
                    else
                    {
                        CompileLiteral(compiler);
                    }
                    compiler.PopScope();
                }
            }
            else
            {
                CompileLiteral(compiler);
            }
        }
Ejemplo n.º 8
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Name))
            {
                Debug.Assert(this.name == null && this.nameStr == null);
                this.nameStr = value;
                this.name    = compiler.CreateXPathQName(this.nameStr);
                Debug.WriteLine("name attribute found: " + this.name);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Select))
            {
                Debug.Assert(this.select == null);
                this.select    = value;
                this.selectKey = compiler.AddQuery(this.select);
                Debug.WriteLine("select attribute = \"" + this.select + "\"  (#" + this.selectKey + ")");
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 9
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Name))
            {
                this.nameAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.Namespace))
            {
                this.nsAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("namespace = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.UseAttributeSets))
            {
                AddAction(compiler.CreateUseAttributeSetsAction());
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Level))
            {
                if (value != s_any && value != s_multiple && value != s_single)
                {
                    throw XsltException.InvalidAttrValue(Keywords.s_Level, value);
                }
                this.level = value;
            }
            else if (Keywords.Equals(name, compiler.Atoms.Count))
            {
                this.countPattern = value;
                this.countKey     = compiler.AddPatternQuery(value, /*allowVars:*/ true, /*allowKey:*/ true);
            }
            else if (Keywords.Equals(name, compiler.Atoms.From))
            {
                this.from    = value;
                this.fromKey = compiler.AddPatternQuery(value, /*allowVars:*/ true, /*allowKey:*/ true);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Value))
            {
                this.value    = value;
                this.valueKey = compiler.AddQuery(value);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Format))
            {
                this.formatAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.Lang))
            {
                this.langAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.LetterValue))
            {
                this.letterAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.GroupingSeparator))
            {
                this.groupingSepAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else if (Keywords.Equals(name, compiler.Atoms.GroupingSize))
            {
                this.groupingSizeAvt = Avt.CompileAvt(compiler, value);
                Debug.WriteLine("name = \"" + value + "\"");
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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();
            }
        }
Ejemplo n.º 13
0
        internal void CompileKey(Compiler compiler)
        {
            NavigatorInput input    = compiler.Input;
            string         element  = input.LocalName;
            int            MatchKey = Compiler.InvalidQueryKey;
            int            UseKey   = Compiler.InvalidQueryKey;

            XmlQualifiedName Name = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    Debug.TraceAttribute(input);

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

                    if (!Keywords.Equals(nspace, input.Atoms.Empty))
                    {
                        continue;
                    }

                    if (Keywords.Equals(name, input.Atoms.Name))
                    {
                        Name = compiler.CreateXPathQName(value);
                    }
                    else if (Keywords.Equals(name, input.Atoms.Match))
                    {
                        MatchKey = compiler.AddPatternQuery(value, /*allowVars:*/ false, /*allowKey*/ false);
                    }
                    else if (Keywords.Equals(name, input.Atoms.Use))
                    {
                        UseKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey*/ false);
                    }
                    else
                    {
                        if (!compiler.ForwardCompatibility)
                        {
                            throw XsltException.InvalidAttribute(element, name);
                        }
                    }
                }while(input.MoveToNextAttribute());
                input.ToParent();
            }

            CheckRequiredAttribute(compiler, MatchKey != Compiler.InvalidQueryKey, Keywords.s_Match);
            CheckRequiredAttribute(compiler, UseKey != Compiler.InvalidQueryKey, Keywords.s_Use);
            CheckRequiredAttribute(compiler, Name != null, Keywords.s_Name);

            compiler.InsertKey(Name, MatchKey, UseKey);
        }
Ejemplo n.º 14
0
        void CompileLiteralAttributesAndNamespaces(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            if (input.Navigator.MoveToAttribute(Keywords.s_UseAttributeSets, input.Atoms.XsltNamespace))
            {
                AddAction(compiler.CreateUseAttributeSetsAction());
                input.Navigator.MoveToParent();
            }
            compiler.InsertExcludedNamespace();

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    // Skip everything from Xslt namespace
                    if (Keywords.Equals(input.NamespaceURI, input.Atoms.XsltNamespace))
                    {
                        continue;
                    }

                    // Add attribute events
                    this.AddEvent(compiler.CreateBeginEvent());
                    this.AddEvents(compiler.CompileAvt(input.Value));
                    this.AddEvent(new EndEvent(XPathNodeType.Attribute));
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }

            if (input.MoveToFirstNamespace())
            {
                do
                {
                    string uri = input.Value;

                    if (Keywords.Compare(uri, input.Atoms.XsltNamespace))
                    {
                        continue;
                    }
                    if (
                        compiler.IsExcludedNamespace(uri) ||
                        compiler.IsExtensionNamespace(uri) ||
                        compiler.IsNamespaceAlias(uri)
                        )
                    {
                        continue;
                    }
                    this.AddEvent(new NamespaceEvent(input));
                }while (input.MoveToNextNamespace());
                input.ToParent();
            }
        }
Ejemplo n.º 15
0
        internal string ResolveAtom(string prefix)
        {
            Debug.Assert(prefix != null && prefix.Length > 0);

            for (NamespaceDecl scope = this.scopes; scope != null; scope = scope.Next)
            {
                if (Keywords.Equals(scope.Prefix, prefix))
                {
                    Debug.Assert(scope.Uri != null);
                    return(scope.Uri);
                }
            }

            return(null);
        }
Ejemplo n.º 16
0
        private void FixupElement()
        {
            Debug.Assert(this.mainNode.NodeType == XmlNodeType.Element);

            if (Keywords.Equals(this.mainNode.NamespaceURI, this.atoms.Empty))
            {
                this.mainNode.Prefix = this.atoms.Empty;
            }

            if (Keywords.Equals(this.mainNode.Prefix, this.atoms.Empty))
            {
                if (Keywords.Equals(this.mainNode.NamespaceURI, this.scopeManager.DefaultNamespace))
                {
                    // Main Node is OK
                }
                else
                {
                    DeclareNamespace(this.mainNode.NamespaceURI, this.mainNode.Prefix);
                }
            }
            else
            {
                bool   thisScope = false;
                string nspace    = this.scopeManager.ResolveNamespace(this.mainNode.Prefix, out thisScope);
                if (nspace != null)
                {
                    if (!Keywords.Equals(this.mainNode.NamespaceURI, nspace))
                    {
                        if (thisScope)      // Prefix conflict
                        {
                            this.mainNode.Prefix = GetPrefixForNamespace(this.mainNode.NamespaceURI);
                        }
                        else
                        {
                            DeclareNamespace(this.mainNode.NamespaceURI, this.mainNode.Prefix);
                        }
                    }
                }
                else
                {
                    DeclareNamespace(this.mainNode.NamespaceURI, this.mainNode.Prefix);
                }
            }

            OutputScope elementScope = this.scopeManager.CurrentElementScope;

            elementScope.Prefix = this.mainNode.Prefix;
        }
Ejemplo n.º 17
0
        internal void CompileSingleTemplate(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            //
            // find mandatory version attribute and launch compilation of single template
            //

            string version = null;
            bool   wrongns = false;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    Debug.TraceAttribute(input);

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

                    if (Keywords.Equals(name, input.Atoms.Version))
                    {
                        if (Keywords.Equals(nspace, input.Atoms.XsltNamespace))
                        {
                            version = input.Value;
                        }
                        else
                        {
                            wrongns = true;
                        }
                    }
                }while(input.MoveToNextAttribute());
                input.ToParent();
            }

            if (version == null)
            {
                if (wrongns)
                {
                    throw new XsltException(Res.Xslt_WrongNamespace);
                }
                throw new XsltException(Res.Xslt_MissingAttribute, Keywords.s_Version);
            }

            Debug.TraceElement(input);

            compiler.AddTemplate(compiler.CreateSingleTemplateAction());
        }
Ejemplo n.º 18
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.DisableOutputEscaping))
            {
                this.disableOutputEscaping = compiler.GetYesNo(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 19
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Match))
            {
                Debug.Assert(this.match == null);
                this.match    = value;
                this.matchKey = compiler.AddPatternQuery(value, /*allowVars:*/ false, /*allowKey:*/ true);
                Debug.WriteLine("match attribute found: \"" + this.match + "\"  (#" + this.matchKey + ")");
            }
            else if (Keywords.Equals(name, compiler.Atoms.Name))
            {
                Debug.Assert(this.name == null);
                this.name = compiler.CreateXPathQName(value);
                Debug.WriteLine("name attribute found: " + this.name);
            }
            else if (Keywords.Equals(name, compiler.Atoms.Priority))
            {
                Debug.Assert(Double.IsNaN(this.priority));
                this.priority = XmlConvert.ToXPathDouble(value);
                if (double.IsNaN(this.priority) && !compiler.ForwardCompatibility)
                {
                    throw XsltException.InvalidAttrValue(Keywords.s_Priority, value);
                }
            }
            else if (Keywords.Equals(name, compiler.Atoms.Mode))
            {
                Debug.Assert(this.mode == null);
                if (compiler.AllowBuiltInMode && value.Trim() == "*")
                {
                    this.mode = Compiler.BuiltInMode;
                }
                else
                {
                    this.mode = compiler.CreateXPathQName(value);
                }
                Debug.WriteLine("mode attribute found: " + this.mode);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 20
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Terminate))
            {
                _Terminate = compiler.GetYesNo(value);
                Debug.WriteLine("Message terminate == \"" + _Terminate + "\"");
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 21
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.UseAttributeSets))
            {
                this.useAttributeSets = value;
                AddAction(compiler.CreateUseAttributeSetsAction());
                Debug.WriteLine("UseAttributeSets = \"" + this.useAttributeSets + "\"");
            }
            else
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 22
0
        internal void CompileNamespaceAlias(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;
            string         element = input.LocalName;
            string         namespace1 = null, namespace2 = null;
            string         prefix1 = null, prefix2 = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    string nspace = input.NamespaceURI;
                    string name   = input.LocalName;

                    if (!Keywords.Equals(nspace, input.Atoms.Empty))
                    {
                        continue;
                    }

                    if (Keywords.Equals(name, input.Atoms.StylesheetPrefix))
                    {
                        prefix1    = input.Value;
                        namespace1 = compiler.GetNsAlias(ref prefix1);
                    }
                    else if (Keywords.Equals(name, input.Atoms.ResultPrefix))
                    {
                        prefix2    = input.Value;
                        namespace2 = compiler.GetNsAlias(ref prefix2);
                    }
                    else
                    {
                        if (!compiler.ForwardCompatibility)
                        {
                            throw XsltException.InvalidAttribute(element, name);
                        }
                    }
                }while(input.MoveToNextAttribute());
                input.ToParent();
            }

            CheckRequiredAttribute(compiler, namespace1, Keywords.s_StylesheetPrefix);
            CheckRequiredAttribute(compiler, namespace2, Keywords.s_ResultPrefix);

            //String[] resultarray = { prefix2, namespace2 };
            compiler.AddNamespaceAlias(namespace1, new NamespaceInfo(prefix2, namespace2, compiler.Stylesheetid));
        }
Ejemplo n.º 23
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Select))
            {
                this.select    = value;
                this.selectKey = compiler.AddQuery(this.select);
                Debug.WriteLine("Select expression == \"" + this.select + "\" + (#" + this.selectKey + ")");
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 24
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Keywords.Equals(name, compiler.Atoms.Name))
            {
                Debug.Assert(this.name == null);
                this.name = compiler.CreateXPathQName(value);
                Debug.WriteLine("Name attribute found: " + this.name);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 25
0
        internal void CompileSelectiveTemplate(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            do
            {
                if (Keywords.Equals(input.NamespaceURI, input.Atoms.XsltNamespace) &&
                    Keywords.Equals(input.LocalName, input.Atoms.Fallback))
                {
                    fallback = true;
                    if (compiler.Recurse())
                    {
                        CompileTemplate(compiler);
                        compiler.ToParent();
                    }
                }
            }while (compiler.Advance());
        }
Ejemplo n.º 26
0
        internal bool FindPrefix(string urn, out string prefix)
        {
            Debug.Assert(urn != null);

            for (NamespaceDecl scope = this.scopes; scope != null; scope = scope.Next)
            {
                if (Keywords.Equals(scope.Uri, urn) &&
                    scope.Prefix != null &&
                    scope.Prefix.Length > 0)
                {
                    prefix = scope.Prefix;
                    return(true);
                }
            }

            prefix = String.Empty;
            return(false);
        }
Ejemplo n.º 27
0
        private void FixupAttributes(int attributeCount)
        {
            for (int attr = 0; attr < attributeCount; attr++)
            {
                Debug.Assert(this.attributeList[attr] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)this.attributeList[attr];


                if (Keywords.Equals(info.NamespaceURI, this.atoms.Empty))
                {
                    info.Prefix = this.atoms.Empty;
                }
                else
                {
                    if (Keywords.Equals(info.Prefix, this.atoms.Empty))
                    {
                        info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                    }
                    else
                    {
                        bool   thisScope = false;
                        string nspace    = this.scopeManager.ResolveNamespace(info.Prefix, out thisScope);
                        if (nspace != null)
                        {
                            if (!Keywords.Equals(info.NamespaceURI, nspace))
                            {
                                if (thisScope)  // prefix conflict
                                {
                                    info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                                }
                                else
                                {
                                    DeclareNamespace(info.NamespaceURI, info.Prefix);
                                }
                            }
                        }
                        else
                        {
                            DeclareNamespace(info.NamespaceURI, info.Prefix);
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
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();
            }
        }
Ejemplo n.º 29
0
        private void BeginNamespace(string name, string nspace)
        {
            bool thisScope = false;

            if (Keywords.Equals(name, this.atoms.Empty))
            {
                if (Keywords.Equals(nspace, this.scopeManager.DefaultNamespace))
                {
                    // Main Node is OK
                }
                else if (Keywords.Equals(this.mainNode.NamespaceURI, this.atoms.Empty))
                {
                    // http://www.w3.org/1999/11/REC-xslt-19991116-errata/ E25
                    // Should throw an error but ingnoring it in Everett.
                    // Would be a breaking change
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            else
            {
                string nspaceDeclared = this.scopeManager.ResolveNamespace(name, out thisScope);
                if (nspaceDeclared != null)
                {
                    if (!Keywords.Equals(nspace, nspaceDeclared))
                    {
                        if (!thisScope)
                        {
                            DeclareNamespace(nspace, name);
                        }
                    }
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            this.currentInfo     = dummy;
            currentInfo.NodeType = XmlNodeType.Attribute;
        }
Ejemplo n.º 30
0
 public string GetNsAlias(ref string prefix)
 {
     Debug.Assert(
         Keywords.Equals(this.input.LocalName, this.input.Atoms.StylesheetPrefix) ||
         Keywords.Equals(this.input.LocalName, this.input.Atoms.ResultPrefix)
         );
     if (Keywords.Compare(this.input.Atoms.HashDefault, prefix))
     {
         prefix = string.Empty;
         return(this.DefaultNamespace);
     }
     else
     {
         if (!PrefixQName.ValidatePrefix(prefix) || prefix.Length == 0)
         {
             throw XsltException.InvalidAttrValue(this.input.LocalName, prefix);
         }
         return(this.ResolveXPathNamespace(prefix));
     }
 }