5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
9 // (C) 2003 Atsushi Enomoto
14 using System.Collections;
15 using System.Collections.Specialized;
17 using System.Xml.Schema;
18 using System.Xml.XPath;
21 using QName = System.Xml.XmlQualifiedName;
23 namespace Mono.Xml.Xsl {
26 XPathExpression usePattern;
27 XPathExpression matchPattern;
29 public XslKey (Compiler c)
31 this.name = c.ParseQNameAttribute ("name");
33 usePattern = c.CompileExpression (c.GetAttribute ("use"));
34 if (usePattern == null)
35 usePattern = c.CompileExpression (".");
37 c.AssertAttribute ("match");
38 this.matchPattern = c.CompileExpression (c.GetAttribute ("match"));
41 public QName Name { get { return name; }}
42 public XPathExpression UsePattern { get { return usePattern; }}
43 public XPathExpression MatchPattern { get { return matchPattern; }}
45 public bool Matches (XPathNavigator nav, string value)
48 if (!nav.Matches (MatchPattern))
50 Debug.WriteLine ("? " + nav.Name);
51 switch (UsePattern.ReturnType)
53 case XPathResultType.NodeSet:
54 XPathNodeIterator matches = nav.Select (UsePattern);
55 while (matches.MoveNext ()) {
56 if (matches.Current.Value == value)
61 case XPathResultType.Any:
63 object o = nav.Evaluate (UsePattern);
64 if (o is XPathNodeIterator) {
65 XPathNodeIterator it = (XPathNodeIterator)o;
66 while (it.MoveNext ())
67 if (it.Current.Value == value)
71 return value == XPathFunctions.ToString (o);
74 return value == nav.EvaluateString (UsePattern, null, null);