private string LookupNamespace(string prefix, int declIndex1)
 {
     if (prefix == null)
     {
         return(null);
     }
     if (prefix == string.Empty)
     {
         return(DefaultNamespace);
     }
     if (Ref.Equal(xml, prefix))
     {
         return(namespaceXml);
     }
     if (Ref.Equal(xmlNs, prefix))
     {
         return(namespaceXmlNs);
     }
     for (int declIndex = declIndex1; declIndex >= 0; declIndex--)
     {
         NsDecl decl = (NsDecl)decls[declIndex];
         if (Ref.Equal(decl.Prefix, prefix) && decl.Uri != null)
         {
             return(decl.Uri);
         }
     }
     return(null);
 }
 /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.LookupPrefix"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual string LookupPrefix(string uri)
 {
     if (uri == null)
     {
         return(null);
     }
     if (DefaultNamespace == uri)
     {
         return(string.Empty);
     }
     if (Ref.Equal(namespaceXml, uri))
     {
         return(xml);
     }
     if (Ref.Equal(namespaceXmlNs, uri))
     {
         return(xmlNs);
     }
     for (int declIndex = decls.Length - 1; declIndex >= 0; declIndex--)
     {
         NsDecl decl = (NsDecl)decls[declIndex];
         if (Ref.Equal(decl.Uri, uri) && decl.Prefix != string.Empty)
         {
             return(decl.Prefix);
         }
     }
     return(null);
 }
示例#3
0
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.XmlNamespaceManager"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlNamespaceManager(XmlNameTable nameTable) {
            this.nameTable = nameTable;
            namespaceXml = nameTable.Add(XmlReservedNs.NsXml);
            namespaceXmlNs = nameTable.Add(XmlReservedNs.NsXmlNs);       
            xml = nameTable.Add("xml");
            xmlNs = nameTable.Add("xmlns");       

            decls = new HWStack(60);
            scopes = new HWStack(60);
            defaultNs = null;
            count = 0;
        }
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.XmlNamespaceManager"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlNamespaceManager(XmlNameTable nameTable)
        {
            this.nameTable = nameTable;
            namespaceXml   = nameTable.Add(XmlReservedNs.NsXml);
            namespaceXmlNs = nameTable.Add(XmlReservedNs.NsXmlNs);
            xml            = nameTable.Add("xml");
            xmlNs          = nameTable.Add("xmlns");

            decls     = new HWStack(60);
            scopes    = new HWStack(60);
            defaultNs = null;
            count     = 0;
        }
 /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.HasNamespace"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual bool HasNamespace(string prefix)
 {
     if (prefix == null)
     {
         return(false);
     }
     for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--)
     {
         NsDecl decl = (NsDecl)decls[declIndex];
         if (Ref.Equal(decl.Prefix, prefix) && decl.Uri != null)
         {
             return(true);
         }
     }
     return(false);
 }
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.GetEnumerator"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual IEnumerator GetEnumerator()
        {
            Hashtable prefixes = new Hashtable(count);

            for (int declIndex = decls.Length - 1; declIndex >= 0; declIndex--)
            {
                NsDecl decl = (NsDecl)decls[declIndex];
                if (decl.Prefix != string.Empty && decl.Uri != null)
                {
                    prefixes[decl.Prefix] = decl.Uri;
                }
            }
            prefixes[string.Empty] = DefaultNamespace;
            prefixes[xml]          = namespaceXml;
            prefixes[xmlNs]        = namespaceXmlNs;
            return(prefixes.Keys.GetEnumerator());
        }
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.PopScope"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual bool PopScope()
        {
            Scope current = (Scope)scopes.Pop();

            if (current == null)
            {
                return(false);
            }
            else
            {
                for (int declIndex = 0; declIndex < count; declIndex++)
                {
                    decls.Pop();
                }
                defaultNs = current.Default;
                count     = current.Count;
                return(true);
            }
        }
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.AddNamespace"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual void AddNamespace(string prefix, string uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            prefix = nameTable.Add(prefix);
            uri    = nameTable.Add(uri);

            if (Ref.Equal(xml, prefix) || Ref.Equal(xmlNs, prefix))
            {
                throw new ArgumentException(Res.GetString(Res.Xml_InvalidPrefix));
            }

            for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--)
            {
                NsDecl decl = (NsDecl)decls[declIndex];
                if (Ref.Equal(decl.Prefix, prefix))
                {
                    decl.Uri = uri;
                    return; // redefine
                }
            } /* else */
            {
                NsDecl decl = (NsDecl)decls.Push();
                if (decl == null)
                {
                    decl = new NsDecl();
                    decls.AddToTop(decl);
                }
                decl.Prefix = prefix;
                decl.Uri    = uri;
                count++;
                if (prefix == string.Empty)
                {
                    defaultNs = decl;
                }
            }
        }
 /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.RemoveNamespace"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual void RemoveNamespace(string prefix, string uri)
 {
     if (uri == null)
     {
         throw new ArgumentNullException("uri");
     }
     if (prefix == null)
     {
         throw new ArgumentNullException("prefix");
     }
     prefix = nameTable.Get(prefix);
     uri    = nameTable.Get(uri);
     if (prefix != null && uri != null)
     {
         for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--)
         {
             NsDecl decl = (NsDecl)decls[declIndex];
             if (Ref.Equal(decl.Prefix, prefix) && Ref.Equal(decl.Uri, uri))
             {
                 decl.Uri = null;
             }
         }
     }
 }
示例#10
0
 private void LoadGlobalVariableOrParameter(NsDecl stylesheetNsList, XslNodeType nodeType)
 {
     Debug.Assert(_curTemplate == null);
     Debug.Assert(_input.CanHaveApplyImports == false);
     VarPar var = XslVarPar();
     // Preserving namespaces to parse content later
     var.Namespaces = MergeNamespaces(var.Namespaces, stylesheetNsList);
     CheckError(!_curStylesheet.AddVarPar(var), /*[XT0630]*/SR.Xslt_DupGlobalVariable, var.Name.QualifiedName);
 }
示例#11
0
 public void AddNamespace(XsltInput input) {
     if (Ref.Equal(input.LocalName, input.Atoms.Xml)) {
         Debug.Assert(input.Value == XmlReservedNs.NsXml, "XmlReader must check binding for 'xml' prefix");
     } else {
         nsList = new NsDecl(nsList, input.LocalName, input.Value);
     }
 }
示例#12
0
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.AddNamespace"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual void AddNamespace(string prefix, string uri) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }
            if (prefix == null) {
                throw new ArgumentNullException("prefix");
            }
            prefix = nameTable.Add(prefix);
            uri = nameTable.Add(uri);

            if (Ref.Equal(xml, prefix) || Ref.Equal(xmlNs, prefix)) {
                throw new ArgumentException(Res.GetString(Res.Xml_InvalidPrefix));
            }

            for(int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex --) {
                NsDecl decl = (NsDecl)decls[declIndex];
                if (Ref.Equal(decl.Prefix, prefix)) {
                    decl.Uri = uri;
                    return; // redefine
                }
            } /* else */ {
                NsDecl decl = (NsDecl) decls.Push();
                if (decl == null) {
                    decl = new NsDecl();
                    decls.AddToTop(decl);
                }
                decl.Prefix = prefix;
                decl.Uri = uri;
                count ++;
                if (prefix == string.Empty) {
                    defaultNs = decl;
                }
            }
        }
示例#13
0
        private void LoadNamespaceAlias(NsDecl stylesheetNsList)
        {
            ContextInfo ctxInfo = _input.GetAttributes(_namespaceAliasAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            string stylesheetNsUri = null;
            string resultPrefix = null;
            string resultNsUri = null;

            if (_input.MoveToXsltAttribute(0, "stylesheet-prefix"))
            {
                if (_input.Value.Length == 0)
                {
                    ReportError(/*[XT_005]*/SR.Xslt_EmptyNsAlias, "stylesheet-prefix");
                }
                else
                {
                    stylesheetNsUri = _input.LookupXmlNamespace(_input.Value == "#default" ? string.Empty : _input.Value);
                }
            }

            if (_input.MoveToXsltAttribute(1, "result-prefix"))
            {
                if (_input.Value.Length == 0)
                {
                    ReportError(/*[XT_005]*/SR.Xslt_EmptyNsAlias, "result-prefix");
                }
                else
                {
                    resultPrefix = _input.Value == "#default" ? string.Empty : _input.Value;
                    resultNsUri = _input.LookupXmlNamespace(resultPrefix);
                }
            }

            CheckNoContent();

            if (stylesheetNsUri == null || resultNsUri == null)
            {
                // At least one of attributes is missing or invalid
                return;
            }
            if (_compiler.SetNsAlias(stylesheetNsUri, resultNsUri, resultPrefix, _curStylesheet.ImportPrecedence))
            {
                // Namespace alias redefinition
                _input.MoveToElement();
                ReportWarning(/*[XT0810]*/SR.Xslt_DupNsAlias, stylesheetNsUri);
            }
        }
示例#14
0
        private void LoadKey(NsDecl stylesheetNsList)
        {
            ContextInfo ctxInfo = _input.GetAttributes(_keyAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            QilName keyName = ParseQNameAttribute(0);
            string match = ParseStringAttribute(1, "match");
            string use = ParseStringAttribute(2, "use");
            string collation = ParseCollationAttribute(3);

            _input.MoveToElement();

            List<XslNode> content = null;

            if (V1)
            {
                if (use == null)
                {
                    _input.SkipNode();
                }
                else
                {
                    CheckNoContent();
                }
            }
            else
            {
                content = LoadInstructions();
                // Load the end tag only if the content is not empty
                if (content.Count != 0)
                {
                    content = LoadEndTag(content);
                }
                if ((use == null) == (content.Count == 0))
                {
                    ReportError(/*[XTSE1205]*/SR.Xslt_KeyCntUse);
                }
                else
                {
                    if (use == null) ReportNYI("xsl:key[count(@use) = 0]");
                }
            }

            Key key = (Key)SetInfo(f.Key(keyName, match, use, _input.XslVersion), null, ctxInfo);

            if (_compiler.Keys.Contains(keyName))
            {
                // Add to the list of previous definitions
                _compiler.Keys[keyName].Add(key);
            }
            else
            {
                // First definition of key with that name
                List<Key> defList = new List<Key>();
                defList.Add(key);
                _compiler.Keys.Add(defList);
            }
        }
示例#15
0
 // NOTE! We inverting namespace order that is irelevant for namespace of the same node, but
 // for included styleseets we don't keep stylesheet as a node and adding it's namespaces to
 // each toplevel element by MergeNamespaces().
 // Namespaces of stylesheet can be overriden in template and to make this works correclety we
 // should attache them after NsDec of top level elements.
 // Toplevel element almost never contais NsDecl and in practice node duplication will not happened, but if they have
 // we should copy NsDecls of stylesheet localy in toplevel elements.
 private static NsDecl MergeNamespaces(NsDecl thisList, NsDecl parentList)
 {
     if (parentList == null)
     {
         return thisList;
     }
     if (thisList == null)
     {
         return parentList;
     }
     // Clone all nodes and attache them to nodes of thisList;
     while (parentList != null)
     {
         bool duplicate = false;
         for (NsDecl tmp = thisList; tmp != null; tmp = tmp.Prev)
         {
             if (Ref.Equal(tmp.Prefix, parentList.Prefix) && (
                 tmp.Prefix != null ||           // Namespace declaration
                 tmp.NsUri == parentList.NsUri   // Extension or excluded namespace
             ))
             {
                 duplicate = true;
                 break;
             }
         }
         if (!duplicate)
         {
             thisList = new NsDecl(thisList, parentList.Prefix, parentList.NsUri);
         }
         parentList = parentList.Prev;
     }
     return thisList;
 }
示例#16
0
        private void LoadFunction(NsDecl stylesheetNsList) {
            Debug.Assert(curTemplate == null);
            ContextInfo ctxInfo = input.GetAttributes(functionAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            QilName name  = ParseQNameAttribute(0);
            string asType = ParseStringAttribute(1, "as");
            bool over     = ParseYesNoAttribute(2, "override") == TriState.True;

            ReportNYI("xsl:function");

            Debug.Assert(input.CanHaveApplyImports == false);

            curFunction = new Object();
            LoadInstructions(InstructionFlags.AllowParam);
            curFunction = null;
        }
        private void LoadNamespaceAlias(NsDecl stylesheetNsList) {
            string attStylesheetPrefix;
            string attResultPrefix    ;

            ContextInfo ctxInfo = input.GetAttributes(/*required:*/2,
                input.Atoms.StylesheetPrefix, out attStylesheetPrefix,
                input.Atoms.ResultPrefix    , out attResultPrefix
            );
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);
            CheckNoContent();

            string stylesheetNsUri  = null;
            string resultNsUri      = null;

            if (attStylesheetPrefix == null) {
                // Attribute is missing
            } else if (attStylesheetPrefix.Length == 0) {
                ReportError(/*[XT_005]*/Res.Xslt_EmptyNsAlias, input.Atoms.StylesheetPrefix);
            } else {
                if (attStylesheetPrefix == "#default") {
                    attStylesheetPrefix = string.Empty;
                }
                stylesheetNsUri = input.LookupXmlNamespace(attStylesheetPrefix);
            }

            if (attResultPrefix == null) {
                // Attribute is missing
            } else if (attResultPrefix.Length == 0) {
                ReportError(/*[XT_005]*/Res.Xslt_EmptyNsAlias, input.Atoms.ResultPrefix);
            } else {
                if (attResultPrefix == "#default") {
                    attResultPrefix = string.Empty;
                }
                resultNsUri = input.LookupXmlNamespace(attResultPrefix);
            }

            if (stylesheetNsUri == null || resultNsUri == null) {
                // At least one of attributes is missing or invalid
                return;
            }
            if (compiler.SetNsAlias(stylesheetNsUri, resultNsUri, attResultPrefix, curStylesheet.ImportPrecedence)) {
                // Namespace alias redefinition
                ReportWarning(/*[XT0810]*/Res.Xslt_DupNsAlias, stylesheetNsUri);
            }
        }
        private void LoadDecimalFormat(NsDecl stylesheetNsList) {
            const int NumAttrs = 11, NumCharAttrs = 8, NumSignAttrs = 7;

            string[] attValues = new string[NumAttrs];
            string[] attNames  = new string[NumAttrs] {
                input.Atoms.DecimalSeparator ,
                input.Atoms.GroupingSeparator,
                input.Atoms.Percent          ,
                input.Atoms.PerMille         ,
                input.Atoms.ZeroDigit        ,
                input.Atoms.Digit            ,
                input.Atoms.PatternSeparator ,
                input.Atoms.MinusSign        ,
                input.Atoms.Infinity         ,
                input.Atoms.NaN              ,
                input.Atoms.Name             ,
            };

            ContextInfo ctxInfo = input.GetAttributes(/*required:*/0, NumAttrs, attNames, attValues);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            // Apply default values
            char[] DefaultValues = DecimalFormatDecl.Default.Characters;
            char[] characters = new char[NumCharAttrs];
            Debug.Assert(NumCharAttrs == DefaultValues.Length);
            int idx;

            for (idx = 0; idx < NumCharAttrs; idx++) {
                characters[idx] = ParseCharAttribute(attValues[idx], DefaultValues[idx], attNames[idx]);
            }

            string attInfinity = attValues[idx++];
            string attNaN      = attValues[idx++];
            string attName     = attValues[idx++];
            Debug.Assert(idx == NumAttrs);

            if (attInfinity == null) {
                attInfinity = DecimalFormatDecl.Default.InfinitySymbol;
            }
            if (attNaN == null) {
                attNaN = DecimalFormatDecl.Default.NanSymbol;
            }

            // Check all NumSignAttrs signs are distinct
            for (int i = 0; i < NumSignAttrs; i++) {
                for (int j = i+1; j < NumSignAttrs; j++) {
                    if (characters[i] == characters[j]) {
                        ReportError(/*[XT1300]*/Res.Xslt_DecimalFormatSignsNotDistinct, attNames[i], attNames[j]);
                        break;
                    }
                }
            }

            XmlQualifiedName name;
            if (attName == null) {
                // Use name="" for the default decimal-format
                name = new XmlQualifiedName();
            } else {
                compiler.EnterForwardsCompatible();
                name = ResolveQName(/*ignoreDefaultNs:*/true, attName);
                if (!compiler.ExitForwardsCompatible(input.ForwardCompatibility)) {
                    name = new XmlQualifiedName();
                }
            }

            if (compiler.DecimalFormats.Contains(name)) {
                // Check all attributes have the same values
                DecimalFormatDecl format = compiler.DecimalFormats[name];
                for (idx = 0; idx < NumCharAttrs; idx++) {
                    if (characters[idx] != format.Characters[idx]) {
                        ReportError(/*[XT1290]*/Res.Xslt_DecimalFormatRedefined, attNames[idx], char.ToString(characters[idx]));
                    }
                }
                if (attInfinity != format.InfinitySymbol) {
                    ReportError(/*[XT1290]*/Res.Xslt_DecimalFormatRedefined, attNames[idx], attInfinity);
                }
                idx++;
                if (attNaN != format.NanSymbol) {
                    ReportError(/*[XT1290]*/Res.Xslt_DecimalFormatRedefined, attNames[idx], attNaN);
                }
                idx++;
                Debug.Assert(name.Equals(format.Name));
                idx++;
                Debug.Assert(idx == NumAttrs);
            } else {
                // Add format to the global collection
                DecimalFormatDecl format = new DecimalFormatDecl(name, attInfinity, attNaN, new string(characters));
                compiler.DecimalFormats.Add(format);
            }
            CheckNoContent();
        }
        private void LoadKey(NsDecl stylesheetNsList) {
            string attName ;
            string attMatch;
            string attUse  ;

            ContextInfo ctxInfo = input.GetAttributes(/*required:*/3,
                input.Atoms.Name , out attName,
                input.Atoms.Match, out attMatch,
                input.Atoms.Use  , out attUse
            );
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);
            CheckNoContent();

            QilName keyName = CreateXPathQName(attName);
            Key key = (Key) SetInfo(f.Key(keyName, attMatch, attUse, input.XslVersion), null, ctxInfo);

            if (compiler.Keys.Contains(keyName)) {
                // Add to the list of previous definitions
                compiler.Keys[keyName].Add(key);
            } else {
                // First definition of key with that name
                List<Key> defList = new List<Key>();
                defList.Add(key);
                compiler.Keys.Add(defList);
            }
        }
        private void LoadPreserveSpace(NsDecl stylesheetNsList) {
            string attElements;
            ContextInfo ctxInfo = input.GetAttributes(/*required:*/1, input.Atoms.Elements, out attElements);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            ParseWhitespaceRules(attElements, true);
            CheckNoContent();
        }
        private void InsertExNamespaces(string value, ref NsDecl nsList, bool extensions) {
            if (value != null && value.Length != 0) {
                compiler.EnterForwardsCompatible();

                string[] list = XmlConvert.SplitString(value);
                for (int idx = 0; idx < list.Length; idx++) {
                    list[idx] = input.LookupXmlNamespace(list[idx] == "#default" ? string.Empty : list[idx]);
                }

                if (!compiler.ExitForwardsCompatible(input.ForwardCompatibility)) {
                    // There were errors in the list, ignore the whole list
                    return;
                }

                for (int idx = 0; idx < list.Length; idx++) {
                    if (list[idx] != null) {
                        nsList = new NsDecl(nsList, /*prefix:*/null, list[idx]);
                        if (extensions) {
                            input.AddExtensionNamespace(list[idx]);
                        }
                    }
                }
            }
        }
示例#22
0
 public void AddNamespace(string prefix, string nsUri) {
     nsList = new NsDecl(nsList, prefix, nsUri);
 }
示例#23
0
        private void LoadTemplate(NsDecl stylesheetNsList)
        {
            Debug.Assert(_curTemplate == null);
            ContextInfo ctxInfo = _input.GetAttributes(_templateAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            string match = ParseStringAttribute(0, "match");
            QilName name = ParseQNameAttribute(1);
            double priority = double.NaN;
            if (_input.MoveToXsltAttribute(2, "priority"))
            {
                priority = XPathConvert.StringToDouble(_input.Value);
                if (double.IsNaN(priority) && !_input.ForwardCompatibility)
                {
                    ReportError(/*[XT0530]*/SR.Xslt_InvalidAttrValue, "priority", _input.Value);
                }
            }
            QilName mode = V1 ? ParseModeAttribute(3) : ParseModeListAttribute(3);

            if (match == null)
            {
                CheckError(!_input.AttributeExists(1, "name"), /*[XT_007]*/SR.Xslt_BothMatchNameAbsent);
                CheckError(_input.AttributeExists(3, "mode"), /*[XT_008]*/SR.Xslt_ModeWithoutMatch);
                mode = nullMode;
                if (_input.AttributeExists(2, "priority"))
                {
                    if (V1)
                    {
                        ReportWarning(/*[XT_008]*/SR.Xslt_PriorityWithoutMatch);
                    }
                    else
                    {
                        ReportError(/*[XT_008]*/SR.Xslt_PriorityWithoutMatch);
                    }
                }
            }

            if (_input.MoveToXsltAttribute(4, "as"))
            {
                ReportNYI("xsl:template/@as");
            }

            _curTemplate = f.Template(name, match, mode, priority, _input.XslVersion);

            // Template without match considered to not have mode and can't call xsl:apply-imports
            _input.CanHaveApplyImports = (match != null);

            SetInfo(_curTemplate,
                LoadEndTag(LoadInstructions(InstructionFlags.AllowParam)), ctxInfo
            );

            if (!_curStylesheet.AddTemplate(_curTemplate))
            {
                ReportError(/*[XT0660]*/SR.Xslt_DupTemplateName, _curTemplate.Name.QualifiedName);
            }
            _curTemplate = null;
        }
示例#24
0
        private void LoadCharacterMap(NsDecl stylesheetNsList) {
            ContextInfo ctxInfo = input.GetAttributes(characterMapAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            QilName name = ParseQNameAttribute(0);
            List<QilName> useCharacterMaps = ParseUseCharacterMaps(1);

            ReportNYI("xsl:character-map");

            QName parentName = input.ElementName;
            if (input.MoveToFirstChild()) {
                do {
                    switch (input.NodeType) {
                    case XmlNodeType.Element:
                        // Only xsl:output-character are allowed here
                        if (input.IsXsltKeyword(atoms.OutputCharacter)) {
                            input.GetAttributes(outputCharacterAttributes);
                            ReportNYI("xsl:output-character");
                            char ch  = ParseCharAttribute(0, "character", /*defVal:*/(char)0);
                            string s = ParseStringAttribute(1, "string");
                            CheckNoContent();
                        } else {
                            ReportError(/*[XT_006]*/SR.Xslt_UnexpectedElement, input.QualifiedName, parentName);
                            input.SkipNode();
                        }
                        break;
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        break;
                    default:
                        Debug.Assert(input.NodeType == XmlNodeType.Text);
                        ReportError(/*[XT_006]*/SR.Xslt_TextNodesNotAllowed, parentName);
                        break;
                    }
                } while (input.MoveToNextSibling());
            }
        }
        private void LoadAttributeSet(NsDecl stylesheetNsList) {
            string attName            ;
            string attUseAttributeSets;

            ContextInfo ctxInfo = input.GetAttributes(/*required:*/1,
                input.Atoms.Name            , out attName            ,
                input.Atoms.UseAttributeSets, out attUseAttributeSets
            );
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            QilName attSetName = CreateXPathQName(attName);
            AttributeSet attSet;
            if (!curStylesheet.AttributeSets.TryGetValue(attSetName, out attSet)) {
                // First definition for attSetName within this stylesheet
                curStylesheet.AttributeSets[attSetName] = attSet = f.AttributeSet(attSetName);
                if (!compiler.AttributeSets.ContainsKey(attSetName)) {
                    // First definition for attSetName overall, adding it to the list here
                    // to ensure stable order of prototemplate functions in QilExpression
                    compiler.AllTemplates.Add(attSet);
                }
            }

            List<XslNode> content = ParseUseAttributeSets(attUseAttributeSets, ctxInfo.lineInfo);
            foreach (XslNode useAttSet in content) {
                Debug.Assert(useAttSet.NodeType == XslNodeType.UseAttributeSet);
                attSet.UsedAttributeSets.Add(useAttSet.Name);
            }

            /* Process children */
            if (input.MoveToFirstChild()) {
                do {
                    switch (input.NodeType) {
                    case XPathNodeType.Element:
                        // Only xsl:attribute's are allowed here
                        if (input.IsXsltNamespace() && input.IsKeyword(input.Atoms.Attribute)) {
                            AddInstruction(content, XslAttribute());
                        } else {
                            ReportError(/*[XT_006]*/Res.Xslt_UnexpectedElement, input.QualifiedName, input.Atoms.AttributeSet);
                            input.SkipNode();
                        }
                        break;
                    case XPathNodeType.Whitespace:
                    case XPathNodeType.SignificantWhitespace:
                        break;
                    default:
                        Debug.Assert(input.NodeType == XPathNodeType.Text);
                        ReportError(/*[XT_006]*/Res.Xslt_TextNodesNotAllowed, input.Atoms.AttributeSet);
                        break;
                    }
                } while (input.MoveToNextSibling());
                input.MoveToParent();
            }
            attSet.AddContent(SetInfo(f.List(), LoadEndTag(content), ctxInfo));
        }
示例#26
0
        private void LoadMsScript(NsDecl stylesheetNsList)
        {
            ContextInfo ctxInfo = _input.GetAttributes(_scriptAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);


            string scriptNs = null;
            if (_input.MoveToXsltAttribute(0, "implements-prefix"))
            {
                if (_input.Value.Length == 0)
                {
                    ReportError(/*[XT_009]*/SR.Xslt_EmptyAttrValue, "implements-prefix", _input.Value);
                }
                else
                {
                    scriptNs = _input.LookupXmlNamespace(_input.Value);
                    if (scriptNs == XmlReservedNs.NsXslt)
                    {
                        ReportError(/*[XT_036]*/SR.Xslt_ScriptXsltNamespace);
                        scriptNs = null;
                    }
                }
            }

            if (scriptNs == null)
            {
                scriptNs = _compiler.CreatePhantomNamespace();
            }
            string language = ParseStringAttribute(1, "language");
            if (language == null)
            {
                language = "jscript";
            }

            if (!_compiler.Settings.EnableScript)
            {
                _compiler.Scripts.ScriptClasses[scriptNs] = null;
                _input.SkipNode();
                return;
            }

            throw new PlatformNotSupportedException("Compiling JScript/CSharp scripts is not supported"); // Not adding any scripts as script compilation is not available
        }
        //: http://www.w3.org/TR/xslt#section-Defining-Template-Rules
        private void LoadTemplate(NsDecl stylesheetNsList) {
            Debug.Assert(curTemplate == null);
            string attMatch   ;
            string attName    ;
            string attPriority;
            string attMode    ;

            ContextInfo ctxInfo = input.GetAttributes(/*required:*/0,
                input.Atoms.Match   , out attMatch   ,
                input.Atoms.Name    , out attName    ,
                input.Atoms.Priority, out attPriority,
                input.Atoms.Mode    , out attMode
            );
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);
            if (attMatch == null) {
                if (attName == null) {
                    ReportError(/*[XT_007]*/Res.Xslt_BothMatchNameAbsent);
                }
                if (attMode != null) {
                    ReportError(/*[XT_008]*/Res.Xslt_ModeWithoutMatch);
                    attMode = null;
                }
                if (attPriority != null) {
                    // In XSLT 2.0 this is an error
                    ReportWarning(/*[XT_008]*/Res.Xslt_PriorityWithoutMatch);
                }
            }

            QilName tmplName = null;
            if (attName != null) {
                compiler.EnterForwardsCompatible();
                tmplName = CreateXPathQName(attName);
                if (!compiler.ExitForwardsCompatible(input.ForwardCompatibility)) {
                    tmplName = null;
                }
            }

            double priority = double.NaN;
            if (attPriority != null) {
                priority = XPathConvert.StringToDouble(attPriority);
                if (double.IsNaN(priority) && !input.ForwardCompatibility) {
                    ReportError(/*[XT0530]*/Res.Xslt_InvalidAttrValue, input.Atoms.Priority, attPriority);
                }
            }

            curTemplate = f.Template(tmplName, attMatch, ParseMode(attMode), priority, input.XslVersion);

            // Template without match considered to not have mode and can't call xsl:apply-imports
            input.CanHaveApplyImports = (attMatch != null);

            SetInfo(curTemplate,
                LoadEndTag(LoadInstructions(InstructionFlags.AllowParam)), ctxInfo
            );

            if (!curStylesheet.AddTemplate(curTemplate)) {
                ReportError(/*[XT0660]*/Res.Xslt_DupTemplateName, curTemplate.Name.QualifiedName);
            }
            curTemplate = null;
        }
示例#28
0
        private void LoadPreserveSpace(NsDecl stylesheetNsList)
        {
            ContextInfo ctxInfo = _input.GetAttributes(_loadStripSpaceAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            if (_input.MoveToXsltAttribute(0, _atoms.Elements))
            {
                ParseWhitespaceRules(_input.Value, true);
            }
            CheckNoContent();
        }
        private void LoadScript(NsDecl stylesheetNsList) {
            string attLanguage        ;
            string attImplementsPrefix;

            ContextInfo ctxInfo = input.GetAttributes(/*required:*/1,
                input.Atoms.ImplementsPrefix, out attImplementsPrefix,
                input.Atoms.Language        , out attLanguage
            );
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            string scriptNs = null;
            if (attImplementsPrefix == null) {
                // Attribute is missing
            } else if (attImplementsPrefix.Length == 0) {
                ReportError(/*[XT_009]*/Res.Xslt_EmptyAttrValue, input.Atoms.ImplementsPrefix, attImplementsPrefix);
            } else {
                scriptNs = input.LookupXmlNamespace(attImplementsPrefix);
                if (scriptNs == XmlReservedNs.NsXslt) {
                    ReportError(/*[XT_036]*/Res.Xslt_ScriptXsltNamespace);
                    scriptNs = null;
                }
            }

            if (scriptNs == null) {
                scriptNs = compiler.CreatePhantomNamespace();
            }
            if (attLanguage == null) {
                attLanguage = "jscript";
            }

            if (! compiler.Settings.EnableScript) {
                compiler.Scripts.ScriptClasses[scriptNs] = null;
                input.SkipNode();
                return;
            }

            ScriptClass     scriptClass;
            StringBuilder   scriptCode  = new StringBuilder();
            string          uriString   = input.Uri;
            int             lineNumber  = 0;
            int             lastEndLine = 0;

            scriptClass = compiler.Scripts.GetScriptClass(scriptNs, attLanguage, (IErrorHelper)this);
            if (scriptClass == null) {
                input.SkipNode();
                return;
            }

            if (input.MoveToFirstChild()) {
                do {
                    switch (input.NodeType) {
                    case XPathNodeType.Text:
                        int startLine = input.StartLine;
                        int endLine   = input.EndLine;
                        if (scriptCode.Length == 0) {
                            lineNumber = startLine;
                        } else if (lastEndLine < startLine) {
                            scriptCode.Append('\n', startLine - lastEndLine);
                        }
                        scriptCode.Append(input.Value);
                        lastEndLine = endLine;
                        break;
                    case XPathNodeType.Element:
                        if (input.IsNs(input.Atoms.UrnMsxsl) && (input.IsKeyword(input.Atoms.Assembly) || input.IsKeyword(input.Atoms.Using))) {
                            if (scriptCode.Length != 0) {
                                ReportError(/*[XT_012]*/Res.Xslt_ScriptNotAtTop, input.QualifiedName);
                                input.SkipNode();
                            }
                            if (input.IsKeyword(input.Atoms.Assembly)) {
                                LoadMsAssembly(scriptClass);
                            } else if (input.IsKeyword(input.Atoms.Using)) {
                                LoadMsUsing(scriptClass);
                            }
                        } else {
                            ReportError(/*[XT_012]*/Res.Xslt_UnexpectedElementQ, input.QualifiedName, "msxsl:script");
                            input.SkipNode();
                        }
                        break;
                    default:
                        Debug.Assert(
                            input.NodeType == XPathNodeType.SignificantWhitespace ||
                            input.NodeType == XPathNodeType.Whitespace
                        );
                        // Skip leading whitespaces
                        if (scriptCode.Length != 0) {
                            goto case XPathNodeType.Text;
                        }
                        break;
                    }
                } while (input.MoveToNextSibling());
                input.MoveToParent();
            }

            if (scriptCode.Length == 0) {
                lineNumber = input.StartLine;
            }
            scriptClass.AddScriptBlock(scriptCode.ToString(), uriString, lineNumber, input.StartLine, input.StartPos);
        }
示例#30
0
        private void LoadDecimalFormat(NsDecl stylesheetNsList)
        {
            const int NumCharAttrs = 8, NumSignAttrs = 7;
            ContextInfo ctxInfo = _input.GetAttributes(_decimalFormatAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            XmlQualifiedName name;
            if (_input.MoveToXsltAttribute(0, "name"))
            {
                _compiler.EnterForwardsCompatible();
                name = ResolveQName(/*ignoreDefaultNs:*/true, _input.Value);
                if (!_compiler.ExitForwardsCompatible(_input.ForwardCompatibility))
                {
                    name = new XmlQualifiedName();
                }
            }
            else
            {
                // Use name="" for the default decimal-format
                name = new XmlQualifiedName();
            }

            string infinity = DecimalFormatDecl.Default.InfinitySymbol;
            if (_input.MoveToXsltAttribute(1, "infinity"))
            {
                infinity = _input.Value;
            }

            string nan = DecimalFormatDecl.Default.NanSymbol;
            if (_input.MoveToXsltAttribute(2, "NaN"))
            {
                nan = _input.Value;
            }

            char[] DefaultValues = DecimalFormatDecl.Default.Characters;
            char[] characters = new char[NumCharAttrs];
            Debug.Assert(NumCharAttrs == DefaultValues.Length);

            for (int idx = 0; idx < NumCharAttrs; idx++)
            {
                characters[idx] = ParseCharAttribute(3 + idx, _decimalFormatAttributes[3 + idx].name, DefaultValues[idx]);
            }

            // Check all NumSignAttrs signs are distinct
            for (int i = 0; i < NumSignAttrs; i++)
            {
                for (int j = i + 1; j < NumSignAttrs; j++)
                {
                    if (characters[i] == characters[j])
                    {
                        // Try move to second attribute and if it is missing to first.
                        bool dummy = _input.MoveToXsltAttribute(3 + j, _decimalFormatAttributes[3 + j].name) || _input.MoveToXsltAttribute(3 + i, _decimalFormatAttributes[3 + i].name);
                        Debug.Assert(dummy, "One of the atts should have lineInfo. if both are defualt they can't conflict.");
                        ReportError(/*[XT1300]*/SR.Xslt_DecimalFormatSignsNotDistinct, _decimalFormatAttributes[3 + i].name, _decimalFormatAttributes[3 + j].name);
                        break;
                    }
                }
            }

            if (_compiler.DecimalFormats.Contains(name))
            {
                // Check all attributes have the same values
                DecimalFormatDecl format = _compiler.DecimalFormats[name];
                _input.MoveToXsltAttribute(1, "infinity");
                CheckError(infinity != format.InfinitySymbol, /*[XT1290]*/SR.Xslt_DecimalFormatRedefined, "infinity", infinity);
                _input.MoveToXsltAttribute(2, "NaN");
                CheckError(nan != format.NanSymbol, /*[XT1290]*/SR.Xslt_DecimalFormatRedefined, "NaN", nan);
                for (int idx = 0; idx < NumCharAttrs; idx++)
                {
                    _input.MoveToXsltAttribute(3 + idx, _decimalFormatAttributes[3 + idx].name);
                    CheckError(characters[idx] != format.Characters[idx], /*[XT1290]*/SR.Xslt_DecimalFormatRedefined, _decimalFormatAttributes[3 + idx].name, char.ToString(characters[idx]));
                }
                Debug.Assert(name.Equals(format.Name));
            }
            else
            {
                // Add format to the global collection
                DecimalFormatDecl format = new DecimalFormatDecl(name, infinity, nan, new string(characters));
                _compiler.DecimalFormats.Add(format);
            }
            CheckNoContent();
        }
示例#31
0
        private void LoadMsScript(NsDecl stylesheetNsList)
        {
            ContextInfo ctxInfo = _input.GetAttributes(_scriptAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);


            string scriptNs = null;
            if (_input.MoveToXsltAttribute(0, "implements-prefix"))
            {
                if (_input.Value.Length == 0)
                {
                    ReportError(/*[XT_009]*/SR.Xslt_EmptyAttrValue, "implements-prefix", _input.Value);
                }
                else
                {
                    scriptNs = _input.LookupXmlNamespace(_input.Value);
                    if (scriptNs == XmlReservedNs.NsXslt)
                    {
                        ReportError(/*[XT_036]*/SR.Xslt_ScriptXsltNamespace);
                        scriptNs = null;
                    }
                }
            }

            if (scriptNs == null)
            {
                scriptNs = _compiler.CreatePhantomNamespace();
            }
            string language = ParseStringAttribute(1, "language");
            if (language == null)
            {
                language = "jscript";
            }

            if (!_compiler.Settings.EnableScript)
            {
                _compiler.Scripts.ScriptClasses[scriptNs] = null;
                _input.SkipNode();
                return;
            }

            ScriptClass scriptClass;
            StringBuilder scriptCode = new StringBuilder();
            string uriString = _input.Uri;
            int lineNumber = 0;
            int lastEndLine = 0;

            scriptClass = _compiler.Scripts.GetScriptClass(scriptNs, language, (IErrorHelper)this);
            if (scriptClass == null)
            {
                _input.SkipNode();
                return;
            }

            QName parentName = _input.ElementName;
            if (_input.MoveToFirstChild())
            {
                do
                {
                    switch (_input.NodeType)
                    {
                        case XmlNodeType.Text:
                            int startLine = _input.Start.Line;
                            int endLine = _input.End.Line;
                            if (scriptCode.Length == 0)
                            {
                                lineNumber = startLine;
                            }
                            else if (lastEndLine < startLine)
                            {
                                // A multiline comment, a PI, or an unrecognized element encountered within
                                // this script block. Insert missed '\n' characters here; otherwise line numbers
                                // in error messages and in the debugger will be screwed up. This action may spoil
                                // the script if the current position is situated in the middle of some identifier
                                // or string literal; however we hope users will not put XML nodes there.
                                scriptCode.Append('\n', startLine - lastEndLine);
                            }
                            scriptCode.Append(_input.Value);
                            lastEndLine = endLine;
                            break;
                        case XmlNodeType.Element:
                            if (_input.IsNs(_atoms.UrnMsxsl) && (_input.IsKeyword(_atoms.Assembly) || _input.IsKeyword(_atoms.Using)))
                            {
                                if (scriptCode.Length != 0)
                                {
                                    ReportError(/*[XT_012]*/SR.Xslt_ScriptNotAtTop, _input.QualifiedName);
                                    _input.SkipNode();
                                }
                                else if (_input.IsKeyword(_atoms.Assembly))
                                {
                                    LoadMsAssembly(scriptClass);
                                }
                                else if (_input.IsKeyword(_atoms.Using))
                                {
                                    LoadMsUsing(scriptClass);
                                }
                            }
                            else
                            {
                                ReportError(/*[XT_012]*/SR.Xslt_UnexpectedElement, _input.QualifiedName, parentName);
                                _input.SkipNode();
                            }
                            break;
                        default:
                            Debug.Assert(
                                _input.NodeType == XmlNodeType.SignificantWhitespace ||
                                _input.NodeType == XmlNodeType.Whitespace
                            );
                            // Skip leading whitespaces
                            if (scriptCode.Length != 0)
                            {
                                goto case XmlNodeType.Text;
                            }
                            break;
                    }
                } while (_input.MoveToNextSibling());
            }

            if (scriptCode.Length == 0)
            {
                lineNumber = _input.Start.Line;
            }
            scriptClass.AddScriptBlock(scriptCode.ToString(), uriString, lineNumber, _input.Start);
        }
示例#32
0
 /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.PopScope"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual bool PopScope() {
     Scope current = (Scope)scopes.Pop();
     if (current == null) {
         return false;
     } 
     else {
         for(int declIndex = 0; declIndex < count; declIndex ++) {
             decls.Pop();
         }
         defaultNs = current.Default;
         count = current.Count;
         return true;
     }
 }
示例#33
0
        private void LoadAttributeSet(NsDecl stylesheetNsList)
        {
            ContextInfo ctxInfo = _input.GetAttributes(_attributeSetAttributes);
            ctxInfo.nsList = MergeNamespaces(ctxInfo.nsList, stylesheetNsList);

            QilName setName = ParseQNameAttribute(0);
            Debug.Assert(setName != null, "Required attribute always != null");

            AttributeSet set;
            if (!_curStylesheet.AttributeSets.TryGetValue(setName, out set))
            {
                set = f.AttributeSet(setName);
                // First definition for setName within this stylesheet
                _curStylesheet.AttributeSets[setName] = set;
                if (!_compiler.AttributeSets.ContainsKey(setName))
                {
                    // First definition for setName overall, adding it to the list here
                    // to ensure stable order of prototemplate functions in QilExpression
                    _compiler.AllTemplates.Add(set);
                }
            }

            List<XslNode> content = new List<XslNode>();
            if (_input.MoveToXsltAttribute(1, "use-attribute-sets"))
            {
                AddUseAttributeSets(content);
            }

            QName parentName = _input.ElementName;
            if (_input.MoveToFirstChild())
            {
                do
                {
                    switch (_input.NodeType)
                    {
                        case XmlNodeType.Element:
                            // Only xsl:attribute's are allowed here
                            if (_input.IsXsltKeyword(_atoms.Attribute))
                            {
                                AddInstruction(content, XslAttribute());
                            }
                            else
                            {
                                ReportError(/*[XT_006]*/SR.Xslt_UnexpectedElement, _input.QualifiedName, parentName);
                                _input.SkipNode();
                            }
                            break;
                        case XmlNodeType.Whitespace:
                        case XmlNodeType.SignificantWhitespace:
                            break;
                        default:
                            Debug.Assert(_input.NodeType == XmlNodeType.Text);
                            ReportError(/*[XT_006]*/SR.Xslt_TextNodesNotAllowed, parentName);
                            break;
                    }
                } while (_input.MoveToNextSibling());
            }
            set.AddContent(SetInfo(f.List(), LoadEndTag(content), ctxInfo));
        }
 private void LoadGlobalVariableOrParameter(NsDecl stylesheetNsList, XslNodeType nodeType) {
     VarPar var = XslVarPar(nodeType);
     // Preserving namespaces to parse content later
     var.Namespaces = MergeNamespaces(var.Namespaces, stylesheetNsList);
     if (!curStylesheet.AddVarPar(var)) {
         ReportError(/*[XT0630]*/Res.Xslt_DupGlobalVariable, var.Name.QualifiedName);
     }
 }
示例#35
0
 public void AddNamespace(string prefix, string nsUri)
 {
     nsList = new NsDecl(nsList, prefix, nsUri);
 }