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;
35 using System.Collections.Specialized;
37 using System.Xml.Schema;
38 using System.Xml.XPath;
40 using Mono.Xml.Xsl.Operations;
42 using QName = System.Xml.XmlQualifiedName;
44 namespace Mono.Xml.Xsl {
45 internal class XslAttributeSet : XslCompiledElement {
47 // [QName]=>XslAttributeSet
48 ArrayList usedAttributeSets = new ArrayList ();
50 // [QName]=>XslAttribute
51 ArrayList attributes = new ArrayList ();
53 public XslAttributeSet (Compiler c) : base (c) {}
59 protected override void Compile (Compiler c)
61 this.name = c.ParseQNameAttribute ("name");
63 QName [] attrSets = c.ParseQNameListAttribute ("use-attribute-sets");
65 foreach (QName q in attrSets)
66 usedAttributeSets.Add (q);
69 if (!c.Input.MoveToFirstChild ()) return;
72 switch (c.Input.NodeType) {
73 case XPathNodeType.Element:
75 case XPathNodeType.Whitespace:
78 if (c.CurrentStylesheet.Version == "1.0")
79 throw new XsltCompileException ("Content " + c.Input.NodeType + " is not allowed in XSLT attribute-set element.", null, c.Input);
83 if (c.Input.NamespaceURI != XsltNamespace || c.Input.LocalName != "attribute")
84 throw new XsltCompileException ("Invalid attr set content", null, c.Input);
85 attributes.Add (new XslAttribute (c));
86 } while (c.Input.MoveToNext ());
88 c.Input.MoveToParent ();
92 public void Merge (XslAttributeSet s)
94 attributes.AddRange (s.attributes);
96 foreach (QName q in s.usedAttributeSets)
97 if (!usedAttributeSets.Contains (q))
98 usedAttributeSets.Add (q);
101 public override void Evaluate (XslTransformProcessor p) {
104 if (usedAttributeSets != null) {
105 for (int i = 0; i < usedAttributeSets.Count; i++) {
106 QName set = (QName) usedAttributeSets [i];
107 XslAttributeSet s = p.ResolveAttributeSet (set);
109 throw new XsltException ("Could not resolve attribute set", null, p.CurrentNode);
112 throw new XsltException ("circular dependency", null, p.CurrentNode);
118 for (int i = 0; i < attributes.Count; i++)
119 ((XslAttribute) attributes [i]).Evaluate (p);