Exemplo n.º 1
0
        private void ProcessTopLevelElements(Compiler c)
        {
            if (!c.Input.MoveToFirstChild())
            {
                return;
            }
            XPathNavigator other = this.HandleIncludesImports(c);

            do
            {
                if (c.Input.NodeType == XPathNodeType.Element && !(c.Input.LocalName != "namespace-alias") && !(c.Input.NamespaceURI != "http://www.w3.org/1999/XSL/Transform"))
                {
                    string text = c.GetAttribute("stylesheet-prefix", string.Empty);
                    if (text == "#default")
                    {
                        text = string.Empty;
                    }
                    string text2 = c.GetAttribute("result-prefix", string.Empty);
                    if (text2 == "#default")
                    {
                        text2 = string.Empty;
                    }
                    this.namespaceAliases.Set(text, text2);
                }
            }while (c.Input.MoveToNext());
            c.Input.MoveTo(other);
            do
            {
                if (c.Input.NodeType == XPathNodeType.Element)
                {
                    this.HandleTopLevelElement(c);
                }
            }while (c.Input.MoveToNext());
            c.Input.MoveToParent();
        }
        public XslTemplate(Compiler c)
        {
            if (c == null)
            {
                return;        // built in template
            }
            this.style = c.CurrentStylesheet;

            c.PushScope();

            if (c.Input.Name == "template" &&
                c.Input.NamespaceURI == Compiler.XsltNamespace &&
                c.Input.MoveToAttribute("mode", String.Empty))
            {
                c.Input.MoveToParent();
                if (!c.Input.MoveToAttribute("match", String.Empty))
                {
                    throw new XsltCompileException("XSLT 'template' element must not have 'mode' attribute when it does not have 'match' attribute", null, c.Input);
                }
                c.Input.MoveToParent();
            }

            if (c.Input.NamespaceURI != Compiler.XsltNamespace)
            {
                this.name  = QName.Empty;
                this.match = c.CompilePattern("/", c.Input);
                this.mode  = QName.Empty;
            }
            else
            {
                this.name  = c.ParseQNameAttribute("name");
                this.match = c.CompilePattern(c.GetAttribute("match"), c.Input);
                this.mode  = c.ParseQNameAttribute("mode");

                string pri = c.GetAttribute("priority");
                if (pri != null)
                {
                    try
                    {
                        this.priority = double.Parse(pri, CultureInfo.InvariantCulture);
                    }
                    catch (FormatException ex)
                    {
                        throw new XsltException("Invalid priority number format", ex, c.Input);
                    }
                }
            }
            Parse(c);

            stackSize = c.PopScope().VariableHighTide;
        }
Exemplo n.º 3
0
        public XslKey(Compiler c)
        {
            this.name            = c.ParseQNameAttribute("name");
            c.KeyCompilationMode = true;
            this.useExpr         = c.CompileExpression(c.GetAttribute("use"));
            if (this.useExpr == null)
            {
                this.useExpr = c.CompileExpression(".");
            }
            c.AssertAttribute("match");
            string attribute = c.GetAttribute("match");

            this.matchPattern    = c.CompilePattern(attribute, c.Input);
            c.KeyCompilationMode = false;
        }
Exemplo n.º 4
0
        private XPathNavigator HandleIncludesImports(Compiler c)
        {
            do
            {
                if (c.Input.NodeType == XPathNodeType.Element)
                {
                    if (c.Input.LocalName != "import" || c.Input.NamespaceURI != "http://www.w3.org/1999/XSL/Transform")
                    {
                        break;
                    }
                    this.HandleImport(c, c.GetAttribute("href"));
                }
            }while (c.Input.MoveToNext());
            XPathNavigator xpathNavigator = c.Input.Clone();

            do
            {
                if (c.Input.NodeType == XPathNodeType.Element && !(c.Input.LocalName != "include") && !(c.Input.NamespaceURI != "http://www.w3.org/1999/XSL/Transform"))
                {
                    this.StoreInclude(c);
                }
            }while (c.Input.MoveToNext());
            c.Input.MoveTo(xpathNavigator);
            return(xpathNavigator);
        }
Exemplo n.º 5
0
        private void ProcessTopLevelElements(Compiler c)
        {
            if (!c.Input.MoveToFirstChild())
            {
                return;
            }

            XPathNavigator saved = HandleIncludesImports(c);

            do
            {
                // Collect namespace aliases first.
                if (c.Input.NodeType != XPathNodeType.Element ||
                    c.Input.LocalName != "namespace-alias" ||
                    c.Input.NamespaceURI != XsltNamespace)
                {
                    continue;
                }
                string sprefix = (string)c.GetAttribute("stylesheet-prefix", "");
                if (sprefix == "#default")
                {
                    sprefix = String.Empty;
                }
                string rprefix = (string)c.GetAttribute("result-prefix", "");
                if (rprefix == "#default")
                {
                    rprefix = String.Empty;
                }
                namespaceAliases.Set(sprefix, rprefix);
            } while (c.Input.MoveToNext());

            c.Input.MoveTo(saved);
            do
            {
                if (c.Input.NodeType != XPathNodeType.Element)
                {
                    continue;
                }
                Debug.EnterNavigator(c);
                this.HandleTopLevelElement(c);
                Debug.ExitNavigator(c);
            } while (c.Input.MoveToNext());

            c.Input.MoveToParent();
        }
Exemplo n.º 6
0
 public XslTemplate(Compiler c)
 {
     if (c == null)
     {
         return;
     }
     this.style = c.CurrentStylesheet;
     c.PushScope();
     if (c.Input.Name == "template" && c.Input.NamespaceURI == "http://www.w3.org/1999/XSL/Transform" && c.Input.MoveToAttribute("mode", string.Empty))
     {
         c.Input.MoveToParent();
         if (!c.Input.MoveToAttribute("match", string.Empty))
         {
             throw new XsltCompileException("XSLT 'template' element must not have 'mode' attribute when it does not have 'match' attribute", null, c.Input);
         }
         c.Input.MoveToParent();
     }
     if (c.Input.NamespaceURI != "http://www.w3.org/1999/XSL/Transform")
     {
         this.name  = XmlQualifiedName.Empty;
         this.match = c.CompilePattern("/", c.Input);
         this.mode  = XmlQualifiedName.Empty;
     }
     else
     {
         this.name  = c.ParseQNameAttribute("name");
         this.match = c.CompilePattern(c.GetAttribute("match"), c.Input);
         this.mode  = c.ParseQNameAttribute("mode");
         string attribute = c.GetAttribute("priority");
         if (attribute != null)
         {
             try
             {
                 this.priority = double.Parse(attribute, CultureInfo.InvariantCulture);
             }
             catch (FormatException innerException)
             {
                 throw new XsltException("Invalid priority number format", innerException, c.Input);
             }
         }
     }
     this.Parse(c);
     this.stackSize = c.PopScope().VariableHighTide;
 }
Exemplo n.º 7
0
		public XslKey (Compiler c)
		{
			this.name = c.ParseQNameAttribute ("name");

			c.KeyCompilationMode = true;
			useExpr = c.CompileExpression (c.GetAttribute ("use"));
			if (useExpr == null)
				useExpr = c.CompileExpression (".");

			c.AssertAttribute ("match");
			string matchString = c.GetAttribute ("match");
			this.matchPattern = c.CompilePattern (matchString, c.Input);
			c.KeyCompilationMode = false;
		}
Exemplo n.º 8
0
        private XPathNavigator HandleIncludesImports(Compiler c)
        {
            // process imports. They must precede to other
            // top level elements by schema.
            do
            {
                if (c.Input.NodeType != XPathNodeType.Element)
                {
                    continue;
                }
                if (c.Input.LocalName != "import" ||
                    c.Input.NamespaceURI != XsltNamespace)
                {
                    break;
                }
                Debug.EnterNavigator(c);
                HandleImport(c, c.GetAttribute("href"));
                Debug.ExitNavigator(c);
            } while (c.Input.MoveToNext());

            XPathNavigator saved = c.Input.Clone();

            // process includes to handle nested imports. They must precede to other
            // top level elements by schema.
            do
            {
                if (c.Input.NodeType != XPathNodeType.Element ||
                    c.Input.LocalName != "include" ||
                    c.Input.NamespaceURI != XsltNamespace)
                {
                    continue;
                }
                Debug.EnterNavigator(c);
                StoreInclude(c);
                Debug.ExitNavigator(c);
            } while (c.Input.MoveToNext());

            c.Input.MoveTo(saved);

            return(saved);
        }
Exemplo n.º 9
0
        public Sort(Compiler c)
        {
            c.CheckExtraAttributes("sort", "select", "lang", "data-type", "order", "case-order");

            expr = c.CompileExpression(c.GetAttribute("select"));
            if (expr == null)
            {
                expr = c.CompileExpression("string(.)");
            }

            langAvt      = c.ParseAvtAttribute("lang");
            dataTypeAvt  = c.ParseAvtAttribute("data-type");
            orderAvt     = c.ParseAvtAttribute("order");
            caseOrderAvt = c.ParseAvtAttribute("case-order");

            // Precalc whatever we can
            lang      = ParseLang(XslAvt.AttemptPreCalc(ref langAvt));
            dataType  = ParseDataType(XslAvt.AttemptPreCalc(ref dataTypeAvt));
            order     = ParseOrder(XslAvt.AttemptPreCalc(ref orderAvt));
            caseOrder = ParseCaseOrder(XslAvt.AttemptPreCalc(ref caseOrderAvt));
        }
Exemplo n.º 10
0
 public Sort(Compiler c)
 {
     c.CheckExtraAttributes("sort", new string[]
     {
         "select",
         "lang",
         "data-type",
         "order",
         "case-order"
     });
     this.expr = c.CompileExpression(c.GetAttribute("select"));
     if (this.expr == null)
     {
         this.expr = c.CompileExpression("string(.)");
     }
     this.langAvt      = c.ParseAvtAttribute("lang");
     this.dataTypeAvt  = c.ParseAvtAttribute("data-type");
     this.orderAvt     = c.ParseAvtAttribute("order");
     this.caseOrderAvt = c.ParseAvtAttribute("case-order");
     this.lang         = this.ParseLang(XslAvt.AttemptPreCalc(ref this.langAvt));
     this.dataType     = this.ParseDataType(XslAvt.AttemptPreCalc(ref this.dataTypeAvt));
     this.order        = this.ParseOrder(XslAvt.AttemptPreCalc(ref this.orderAvt));
     this.caseOrder    = this.ParseCaseOrder(XslAvt.AttemptPreCalc(ref this.caseOrderAvt));
 }
Exemplo n.º 11
0
		private XPathNavigator HandleIncludesImports (Compiler c)
		{
			// process imports. They must precede to other
			// top level elements by schema.
			do {
				if (c.Input.NodeType != XPathNodeType.Element)
					continue;
				if (c.Input.LocalName != "import" ||
					c.Input.NamespaceURI != XsltNamespace)
					break;
				Debug.EnterNavigator (c);
				HandleImport (c, c.GetAttribute ("href"));
				Debug.ExitNavigator (c);
			} while (c.Input.MoveToNext ());

			XPathNavigator saved = c.Input.Clone ();

			// process includes to handle nested imports. They must precede to other
			// top level elements by schema.
			do {
				if (c.Input.NodeType != XPathNodeType.Element ||
					c.Input.LocalName != "include" ||
					c.Input.NamespaceURI != XsltNamespace)
					continue;
				Debug.EnterNavigator (c);
				StoreInclude (c);
				Debug.ExitNavigator (c);
			} while (c.Input.MoveToNext ());

			c.Input.MoveTo (saved);

			return saved;
		}
Exemplo n.º 12
0
		private void ProcessTopLevelElements (Compiler c)
		{
			if (!c.Input.MoveToFirstChild ())
				return;

			XPathNavigator saved = HandleIncludesImports (c);

			do {
				// Collect namespace aliases first.
				if (c.Input.NodeType != XPathNodeType.Element ||
					c.Input.LocalName != "namespace-alias" ||
					c.Input.NamespaceURI != XsltNamespace)
					continue;
				string sprefix = (string) c.GetAttribute ("stylesheet-prefix", "");
				if (sprefix == "#default")
					sprefix = String.Empty;
				string rprefix= (string) c.GetAttribute ("result-prefix", "");
				if (rprefix == "#default")
					rprefix = String.Empty;
				namespaceAliases.Set (sprefix, rprefix);
			} while (c.Input.MoveToNext ());

			c.Input.MoveTo (saved);
			do {
				if (c.Input.NodeType != XPathNodeType.Element)
					continue;
				Debug.EnterNavigator (c);
				this.HandleTopLevelElement (c);
				Debug.ExitNavigator (c);
			} while (c.Input.MoveToNext ());
			
			c.Input.MoveToParent ();
		}
Exemplo n.º 13
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;
		}
Exemplo n.º 14
0
		public XslTemplate (Compiler c)
		{
			if (c == null) return; // built in template
			this.style = c.CurrentStylesheet;
			
			c.PushScope ();

			if (c.Input.Name == "template" &&
			    c.Input.NamespaceURI == Compiler.XsltNamespace &&
			    c.Input.MoveToAttribute ("mode", String.Empty)) {
				c.Input.MoveToParent ();
				if (!c.Input.MoveToAttribute ("match", String.Empty))
					throw new XsltCompileException ("XSLT 'template' element must not have 'mode' attribute when it does not have 'match' attribute", null, c.Input);
				c.Input.MoveToParent ();
			}

			if (c.Input.NamespaceURI != Compiler.XsltNamespace) {
				this.name = QName.Empty;
				this.match = c.CompilePattern ("/", c.Input);
				this.mode = QName.Empty;
			} else {
				this.name = c.ParseQNameAttribute ("name");
				this.match = c.CompilePattern (c.GetAttribute ("match"), c.Input);
				this.mode = c.ParseQNameAttribute ("mode");
				
				string pri = c.GetAttribute ("priority");
				if (pri != null) {
					try {
						this.priority = double.Parse (pri, CultureInfo.InvariantCulture);
					} catch (FormatException ex) {
						throw new XsltException ("Invalid priority number format", ex, c.Input);
					}
				}
			}
			Parse (c);
			
			stackSize = c.PopScope ().VariableHighTide;
			
		}
Exemplo n.º 15
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;
 }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
0
		public Sort (Compiler c)
		{
			c.CheckExtraAttributes ("sort", "select", "lang", "data-type", "order", "case-order");
			
			expr = c.CompileExpression (c.GetAttribute ("select"));
			if (expr == null)
				expr = c.CompileExpression ("string(.)");
			
			langAvt = c.ParseAvtAttribute ("lang");
			dataTypeAvt = c.ParseAvtAttribute ("data-type");
			orderAvt = c.ParseAvtAttribute ("order");
			caseOrderAvt = c.ParseAvtAttribute ("case-order");
			
			// Precalc whatever we can
			lang = ParseLang (XslAvt.AttemptPreCalc (ref langAvt));
			dataType = ParseDataType (XslAvt.AttemptPreCalc (ref dataTypeAvt));
			order = ParseOrder (XslAvt.AttemptPreCalc (ref orderAvt));
			caseOrder = ParseCaseOrder (XslAvt.AttemptPreCalc (ref caseOrderAvt));
		}