2 // XslTemplateContent.cs
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
9 // (C) 2003 Atsushi Enomoto
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
36 using System.Xml.XPath;
39 namespace Mono.Xml.Xsl.Operations
41 internal class XslTemplateContent : XslCompiledElementBase
43 ArrayList content = new ArrayList ();
47 XPathNodeType parentType;
50 public XslTemplateContent (Compiler c,
51 XPathNodeType parentType, bool xslForEach)
54 this.parentType = parentType;
55 this.xslForEach = xslForEach;
59 public XPathNodeType ParentType {
60 get { return parentType; }
63 protected override void Compile (Compiler c)
65 if (c.Debugger != null)
66 c.Debugger.DebugCompile (this.DebugInput);
68 hasStack = (c.CurrentVariableScope == null);
71 Debug.EnterNavigator (c);
72 XPathNavigator n = c.Input;
74 case XPathNodeType.Element:
75 switch (n.NamespaceURI) {
78 switch (n.LocalName) {
80 content.Add (new XslApplyImports (c));
82 case "apply-templates":
83 content.Add (new XslApplyTemplates (c));
86 if (ParentType == XPathNodeType.All
87 || ParentType == XPathNodeType.Element)
88 content.Add (new XslAttribute (c));
91 content.Add (new XslCallTemplate (c));
94 content.Add (new XslChoose (c));
97 if (ParentType == XPathNodeType.All
98 || ParentType == XPathNodeType.Element)
99 content.Add (new XslComment (c));
102 content.Add (new XslCopy (c));
105 content.Add (new XslCopyOf (c));
108 if (ParentType == XPathNodeType.All
109 || ParentType == XPathNodeType.Element)
110 content.Add (new XslElement (c));
115 content.Add (new XslForEach (c));
118 content.Add (new XslIf (c));
121 content.Add (new XslMessage(c));
124 content.Add (new XslNumber(c));
126 case "processing-instruction":
127 if (ParentType == XPathNodeType.All
128 || ParentType == XPathNodeType.Element)
129 content.Add (new XslProcessingInstruction(c));
132 content.Add (new XslText(c, false));
135 content.Add (new XslValueOf(c));
138 content.Add (new XslLocalVariable (c));
143 throw new XsltCompileException ("'sort' element is not allowed here as a templete content", null, n);
145 // TODO: handle fallback, like we should
146 // throw new XsltCompileException ("Did not recognize element " + n.Name, null, n);
147 content.Add (new XslNotSupportedOperation (c));
152 if (!c.IsExtensionNamespace (n.NamespaceURI))
153 content.Add (new XslLiteralElement(c));
155 if (n.MoveToFirstChild ()) {
157 if (n.NamespaceURI == XsltNamespace && n.LocalName == "fallback")
158 content.Add (new XslFallback (c));
159 } while (n.MoveToNext ());
167 case XPathNodeType.SignificantWhitespace:
168 content.Add (new XslText(c, true));
170 case XPathNodeType.Text:
171 content.Add (new XslText(c, false));
177 Debug.ExitNavigator (c);
179 } while (c.Input.MoveToNext ());
183 stackSize = c.PopScope ().VariableHighTide;
184 hasStack = stackSize > 0;
189 public override void Evaluate (XslTransformProcessor p)
191 if (p.Debugger != null)
192 p.Debugger.DebugExecute (p, this.DebugInput);
195 p.PushStack (stackSize);
197 int len = content.Count;
198 for (int i = 0; i < len; i++)
199 ((XslOperation) content [i]).Evaluate (p);