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 {
40 internal class XslTemplateContent : XslCompiledElement {
41 ArrayList content = new ArrayList ();
46 public XslTemplateContent (Compiler c, XPathNodeType parentType)
47 : base (c, parentType)
51 private void ThrowIfNotElement (Compiler c)
54 case XPathNodeType.All:
55 case XPathNodeType.Element:
58 throw new XsltCompileException ("Cannot contain attribute from this parent node " + ParentType, null, c.Input);
62 protected override void Compile (Compiler c)
64 hasStack = (c.CurrentVariableScope == null);
67 Debug.EnterNavigator (c);
68 XPathNavigator n = c.Input;
70 case XPathNodeType.Element:
71 switch (n.NamespaceURI) {
74 switch (n.LocalName) {
76 content.Add (new XslApplyImports (c));
78 case "apply-templates":
79 content.Add (new XslApplyTemplates (c));
82 ThrowIfNotElement (c);
83 content.Add (new XslAttribute (c));
86 content.Add (new XslCallTemplate (c));
89 content.Add (new XslChoose (c));
92 ThrowIfNotElement (c);
93 content.Add (new XslComment (c));
96 content.Add (new XslCopy (c));
99 content.Add (new XslCopyOf (c));
102 ThrowIfNotElement (c);
103 content.Add (new XslElement (c));
106 content.Add (new XslFallback (c));
109 content.Add (new XslForEach (c));
112 content.Add (new XslIf (c));
115 content.Add (new XslMessage(c));
118 content.Add (new XslNumber(c));
120 case "processing-instruction":
121 ThrowIfNotElement (c);
122 content.Add (new XslProcessingInstruction(c));
125 content.Add (new XslText(c, false));
128 content.Add (new XslValueOf(c));
131 content.Add (new XslLocalVariable (c));
134 // TODO: handle fallback, like we should
135 throw new XsltCompileException ("Did not recognize element " + n.Name, null, n);
139 if (!c.IsExtensionNamespace (n.NamespaceURI))
140 content.Add (new XslLiteralElement(c));
142 if (n.MoveToFirstChild ()) {
144 if (n.NamespaceURI == XsltNamespace && n.LocalName == "fallback")
145 content.Add (new XslFallback (c));
146 } while (n.MoveToNext ());
154 case XPathNodeType.SignificantWhitespace:
155 content.Add (new XslText(c, true));
157 case XPathNodeType.Text:
158 content.Add (new XslText(c, false));
164 Debug.ExitNavigator (c);
166 } while (c.Input.MoveToNext ());
170 stackSize = c.PopScope ().VariableHighTide;
171 hasStack = stackSize > 0;
176 public override void Evaluate (XslTransformProcessor p)
179 p.PushStack (stackSize);
181 int len = content.Count;
182 for (int i = 0; i < len; i++)
183 ((XslOperation) content [i]).Evaluate (p);