Browse Source

2003-11-19 Atsushi Enomoto <[email protected]>

	* IdPattern.cs,
	  KeyPattern.cs : Implemented Matches(), overrode DefaultPriority,
	  modified inheritance.
	* Pattern.cs : Added id and key pattern support.

svn path=/trunk/mcs/; revision=20223
Atsushi Eno 22 years ago
parent
commit
5f185b2cce

+ 7 - 0
mcs/class/System.XML/Mono.Xml.XPath/ChangeLog

@@ -1,3 +1,10 @@
+2003-11-19  Atsushi Enomoto <[email protected]>
+
+	* IdPattern.cs,
+	  KeyPattern.cs : Implemented Matches(), overrode DefaultPriority,
+	  modified inheritance.
+	* Pattern.cs : Added id and key pattern support.
+
 2003-11-02  Atsushi Enomoto <[email protected]>
 
 	* DTMXPathNavigator.cs : Fixed MoveToNamespace() that might result in

+ 7 - 2
mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs

@@ -16,18 +16,23 @@ using System.Xml.XPath;
 using System.Xml.Xsl;
 
 namespace Mono.Xml.XPath {
-	internal class IdPattern : Pattern {
+	internal class IdPattern : LocationPathPattern {
 
 		string arg0;
 		
 		public IdPattern (string arg0)
+			: base ((NodeTest) null)
 		{
 			this.arg0 = arg0;
 		}
 		
 		public override bool Matches (XPathNavigator node, XsltContext ctx)
 		{
-			throw new NotImplementedException ();
+			XPathNavigator tmp = node.Clone ();
+			tmp.MoveToId (arg0);
+			return tmp.IsSamePosition (node);
 		}
+
+		public override double DefaultPriority { get { return 0.5; } }
 	}
 }

+ 22 - 5
mcs/class/System.XML/Mono.Xml.XPath/KeyPattern.cs

@@ -14,21 +14,38 @@ using System.Xml;
 using System.Xml.Schema;
 using System.Xml.XPath;
 using System.Xml.Xsl;
+using Mono.Xml.Xsl;
+using Mono.Xml.Xsl.Functions;
 
 namespace Mono.Xml.XPath {
-	internal class KeyPattern : Pattern {
+	internal class KeyPattern : LocationPathPattern {
 
+		XmlQualifiedName keyName;
 		string arg0, arg1;
+		XsltKey key;
 		
-		public KeyPattern (string arg0, string arg1)
+		public KeyPattern (XsltKey key)
+			: base ((NodeTest) null)
 		{
-			this.arg0 = arg0;
-			this.arg1 = arg1;
+			this.key = key;
+			ExprLiteral keyName = key.KeyName as ExprLiteral;
+			ExprLiteral field = key.Field as ExprLiteral;
+			this.arg0 = keyName.Value;
+			this.arg1 = field.Value;
+			this.keyName = XslNameUtil.FromString (arg0, key.NamespaceManager);
 		}
 		
 		public override bool Matches (XPathNavigator node, XsltContext ctx)
 		{
-			throw new NotImplementedException ();
+			XsltCompiledContext xctx = ctx as XsltCompiledContext;
+			XslKey xslkey = xctx.Processor.CompiledStyle.Keys [keyName] as XslKey;
+			XPathNodeIterator iter = key.EvaluateNodeSet (new SelfIterator (node, ctx));
+			if (iter.MoveNext ())
+				return iter.Current.IsSamePosition (node);
+			else
+				return false;
 		}
+
+		public override double DefaultPriority { get { return 0.5; } }
 	}
 }

+ 12 - 2
mcs/class/System.XML/Mono.Xml.XPath/Pattern.cs

@@ -15,6 +15,7 @@ using System.Xml.Schema;
 using System.Xml.XPath;
 using System.Xml.Xsl;
 using Mono.Xml.Xsl;
+using Mono.Xml.Xsl.Functions;
 
 namespace Mono.Xml.XPath {
 	public abstract class Pattern {
@@ -70,8 +71,17 @@ namespace Mono.Xml.XPath {
 				return p1;
 			}
 			
-			// TODO: Handle ID/KEY
-			
+			if (e is XPathFunctionId)
+			{
+				ExprLiteral id = ((XPathFunctionId) e).Id as ExprLiteral;
+				return new IdPattern (id.Value);
+			}
+
+			if (e is XsltKey)
+			{
+				return new KeyPattern ((XsltKey) e);
+			}
+
 			throw new Exception ("Invalid Pattern");
 		}