Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        internal string GetSingleAttribute(string attributeAtom)
        {
            NavigatorInput input   = Input;
            string         element = input.LocalName;
            string         value   = null;

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

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

                    if (Keywords.Equals(name, attributeAtom))
                    {
                        value = input.Value;
                    }
                    else
                    {
                        if (!this.ForwardCompatibility)
                        {
                            throw XsltException.InvalidAttribute(element, name);
                        }
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }

            if (value == null)
            {
                throw new XsltException(Res.Xslt_MissingAttribute, attributeAtom);
            }
            return(value);
        }
Exemplo n.º 4
0
        public void CompileAttributes(Compiler compiler)
        {
            NavigatorInput input   = compiler.Input;
            string         element = input.LocalName;

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

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

                    try {
                        if (CompileAttribute(compiler) == false)
                        {
                            throw XsltException.InvalidAttribute(element, input.LocalName);
                        }
                    }catch (Exception) {
                        if (!compiler.ForwardCompatibility)
                        {
                            throw;
                        }
                        else
                        {
                            // In ForwardCompatibility mode we ignoreing all unknown or incorrect attributes
                            // If it's mandatory attribute we'l notice it absents later.
                        }
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }
        }
Exemplo n.º 5
0
        internal void CompileStylesheetAttributes(Compiler compiler)
        {
            NavigatorInput input        = compiler.Input;
            string         element      = input.LocalName;
            string         badAttribute = null;
            string         version      = null;

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

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

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

                    Debug.WriteLine("Attribute name: \"" + name + "\"");
                    if (Keywords.Equals(name, input.Atoms.Version))
                    {
                        version = input.Value;
                        if (1 <= XmlConvert.ToXPathDouble(version))
                        {
                            compiler.ForwardCompatibility = (version != Keywords.s_Version10);
                        }
                        else
                        {
                            // XmlConvert.ToXPathDouble(version) an be NaN!
                            if (!compiler.ForwardCompatibility)
                            {
                                throw XsltException.InvalidAttrValue(Keywords.s_Version, version);
                            }
                        }
                        Debug.WriteLine("Version found: \"" + version + "\"");
                    }
                    else if (Keywords.Equals(name, input.Atoms.ExtensionElementPrefixes))
                    {
                        compiler.InsertExtensionNamespace(input.Value);
                    }
                    else if (Keywords.Equals(name, input.Atoms.ExcludeResultPrefixes))
                    {
                        compiler.InsertExcludedNamespace(input.Value);
                    }
                    else if (Keywords.Equals(name, input.Atoms.Id))
                    {
                        // Do nothing here.
                    }
                    else
                    {
                        // We can have version atribute later. For now remember this attribute and continue
                        badAttribute = name;
                    }
                }while(input.MoveToNextAttribute());
                input.ToParent();
            }

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

            if (badAttribute != null && !compiler.ForwardCompatibility)
            {
                throw XsltException.InvalidAttribute(element, badAttribute);
            }
        }