Esempio n. 1
0
        internal void Compile(Compiler c)
        {
            c.PushStylesheet(this);

            templates = new XslTemplateTable(this);
            baseURI   = c.Input.BaseURI;

            // move to root element
            while (c.Input.NodeType != XPathNodeType.Element)
            {
                if (!c.Input.MoveToNext())
                {
                    throw new XsltCompileException("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, c.Input);
                }
            }

            if (c.Input.NamespaceURI != XsltNamespace)
            {
                if (c.Input.GetAttribute("version", XsltNamespace) == String.Empty)
                {
                    throw new XsltCompileException("Mandatory global attribute version is missing", null, c.Input);
                }
                // then it is simplified stylesheet.
                templates.Add(new XslTemplate(c));
            }
            else
            {
                if (c.Input.LocalName != "stylesheet" &&
                    c.Input.LocalName != "transform")
                {
                    throw new XsltCompileException("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, c.Input);
                }

                version = c.Input.GetAttribute("version", "");
                if (version == String.Empty)
                {
                    throw new XsltCompileException("Mandatory attribute version is missing", null, c.Input);
                }

                extensionElementPrefixes = ParseMappedPrefixes(c.GetAttribute("extension-element-prefixes"), c.Input);
                excludeResultPrefixes    = ParseMappedPrefixes(c.GetAttribute("exclude-result-prefixes"), c.Input);
                if (c.Input.MoveToFirstNamespace(XPathNamespaceScope.Local))
                {
                    do
                    {
                        if (c.Input.Value == XsltNamespace)
                        {
                            continue;
                        }
                        this.stylesheetNamespaces.Insert(0, new QName(c.Input.Name, c.Input.Value));
                    } while (c.Input.MoveToNextNamespace(XPathNamespaceScope.Local));
                    c.Input.MoveToParent();
                }
                ProcessTopLevelElements(c);
            }

            foreach (XslGlobalVariable v in variables.Values)
            {
                c.AddGlobalVariable(v);
            }
            foreach (ArrayList al in keys.Values)
            {
                for (int i = 0; i < al.Count; i++)
                {
                    c.AddKey((XslKey)al[i]);
                }
            }

            c.PopStylesheet();
            inProcessIncludes = null;
        }
		internal void Compile (Compiler c)
		{
			c.PushStylesheet (this);
			
			templates = new XslTemplateTable (this);
			baseURI = c.Input.BaseURI;

			// move to root element
			while (c.Input.NodeType != XPathNodeType.Element)
				if (!c.Input.MoveToNext ())
					throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, c.Input);

			if (c.Input.NamespaceURI != XsltNamespace) {
				if (c.Input.GetAttribute ("version", XsltNamespace) == String.Empty)
					throw new XsltCompileException ("Mandatory global attribute version is missing", null, c.Input);
				// then it is simplified stylesheet.
				templates.Add (new XslTemplate (c));
			} else {
				if (c.Input.LocalName != "stylesheet" &&
					c.Input.LocalName != "transform")
					throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, c.Input);

				version = c.Input.GetAttribute ("version", "");
				if (version == String.Empty)
					throw new XsltCompileException ("Mandatory attribute version is missing", null, c.Input);

				extensionElementPrefixes = ParseMappedPrefixes (c.GetAttribute ("extension-element-prefixes"), c.Input);
				excludeResultPrefixes = ParseMappedPrefixes (c.GetAttribute ("exclude-result-prefixes"), c.Input);
				if (c.Input.MoveToFirstNamespace (XPathNamespaceScope.Local)) {
					do {
						if (c.Input.Value == XsltNamespace)
							continue;
						this.stylesheetNamespaces.Insert (0, new QName (c.Input.Name, c.Input.Value));
					} while (c.Input.MoveToNextNamespace (XPathNamespaceScope.Local));
					c.Input.MoveToParent ();
				}
				ProcessTopLevelElements (c);
			}

			foreach (XslGlobalVariable v in variables.Values)
				c.AddGlobalVariable (v);
			foreach (ArrayList al in keys.Values)
				for (int i = 0; i < al.Count; i++)
					c.AddKey ((XslKey) al[i]);

			c.PopStylesheet ();
			inProcessIncludes = null;
		}
Esempio n. 3
0
 internal void Compile(Compiler c)
 {
     c.PushStylesheet(this);
     this.templates = new XslTemplateTable(this);
     this.baseURI   = c.Input.BaseURI;
     while (c.Input.NodeType != XPathNodeType.Element)
     {
         if (!c.Input.MoveToNext())
         {
             throw new XsltCompileException("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, c.Input);
         }
     }
     if (c.Input.NamespaceURI != "http://www.w3.org/1999/XSL/Transform")
     {
         if (c.Input.GetAttribute("version", "http://www.w3.org/1999/XSL/Transform") == string.Empty)
         {
             throw new XsltCompileException("Mandatory global attribute version is missing", null, c.Input);
         }
         this.templates.Add(new XslTemplate(c));
     }
     else
     {
         if (c.Input.LocalName != "stylesheet" && c.Input.LocalName != "transform")
         {
             throw new XsltCompileException("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element", null, c.Input);
         }
         this.version = c.Input.GetAttribute("version", string.Empty);
         if (this.version == string.Empty)
         {
             throw new XsltCompileException("Mandatory attribute version is missing", null, c.Input);
         }
         this.extensionElementPrefixes = this.ParseMappedPrefixes(c.GetAttribute("extension-element-prefixes"), c.Input);
         this.excludeResultPrefixes    = this.ParseMappedPrefixes(c.GetAttribute("exclude-result-prefixes"), c.Input);
         if (c.Input.MoveToFirstNamespace(XPathNamespaceScope.Local))
         {
             do
             {
                 if (!(c.Input.Value == "http://www.w3.org/1999/XSL/Transform"))
                 {
                     this.stylesheetNamespaces.Insert(0, new XmlQualifiedName(c.Input.Name, c.Input.Value));
                 }
             }while (c.Input.MoveToNextNamespace(XPathNamespaceScope.Local));
             c.Input.MoveToParent();
         }
         this.ProcessTopLevelElements(c);
     }
     foreach (object obj in this.variables.Values)
     {
         XslGlobalVariable var = (XslGlobalVariable)obj;
         c.AddGlobalVariable(var);
     }
     foreach (object obj2 in this.keys.Values)
     {
         ArrayList arrayList = (ArrayList)obj2;
         for (int i = 0; i < arrayList.Count; i++)
         {
             c.AddKey((XslKey)arrayList[i]);
         }
     }
     c.PopStylesheet();
     this.inProcessIncludes = null;
 }