Просмотр исходного кода

2005-08-05 Atsushi Enomoto <[email protected]>

	* Pattern.cs, IdPattern.cs, LocationPathPattern.cs, UnionPattern.cs :
	  added bool EvaluatedNodeType property (used in XslKeyTable).

	* XslKey.cs : Fixed match pattern in xsl:key to check attribute nodes.
	  To minimize attribute iteration, use Pattern.EvaluatedNodeType.
	  Fixed bug #75709.


svn path=/trunk/mcs/; revision=48031
Atsushi Eno 20 лет назад
Родитель
Сommit
317a5a4282

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

@@ -1,3 +1,8 @@
+2005-08-05  Atsushi Enomoto  <[email protected]>
+
+	* Pattern.cs, IdPattern.cs, LocationPathPattern.cs, UnionPattern.cs :
+	  added bool EvaluatedNodeType property (used in XslKeyTable).
+
 2005-05-05  Atsushi Enomoto  <[email protected]>
 
 	* XPathEditableDocument.cs : sync with updated 2.0 API.

+ 5 - 1
mcs/class/System.XML/Mono.Xml.XPath/IdPattern.cs

@@ -47,7 +47,11 @@ namespace Mono.Xml.XPath {
 		{
 			ids = arg0.Split (XmlChar.WhitespaceChars);
 		}
-		
+
+		public override XPathNodeType EvaluatedNodeType {
+			get { return XPathNodeType.Element; }
+		}
+
 		public override bool Matches (XPathNavigator node, XsltContext ctx)
 		{
 			XPathNavigator tmp = ((XsltCompiledContext) ctx).GetNavCache (this, node);

+ 4 - 0
mcs/class/System.XML/Mono.Xml.XPath/LocationPathPattern.cs

@@ -82,6 +82,10 @@ namespace Mono.Xml.XPath {
 				return .5;
 			}
 		}
+
+		public override XPathNodeType EvaluatedNodeType {
+			get { return nodeTest.EvaluatedNodeType; }
+		}
 		
 		public override bool Matches (XPathNavigator node, XsltContext ctx)
 		{

+ 5 - 1
mcs/class/System.XML/Mono.Xml.XPath/Pattern.cs

@@ -107,7 +107,11 @@ namespace Mono.Xml.XPath
 		}
 		
 		public virtual double DefaultPriority { get { return 0.5; }}
-		
+
+		public virtual XPathNodeType EvaluatedNodeType {
+			get { return XPathNodeType.All; }
+		}
+
 		public abstract bool Matches (XPathNavigator node, XsltContext ctx);
 	}
 }

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

@@ -46,6 +46,13 @@ namespace Mono.Xml.XPath {
 			this.p0 = p0;
 			this.p1 = p1;
 		}
+
+		public override XPathNodeType EvaluatedNodeType {
+			get {
+				return p0.EvaluatedNodeType == p1.EvaluatedNodeType ?
+					p0.EvaluatedNodeType : XPathNodeType.All;
+			}
+		}
 		
 		public override bool Matches (XPathNavigator node, XsltContext ctx)
 		{

+ 6 - 0
mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog

@@ -1,3 +1,9 @@
+2005-08-05  Atsushi Enomoto  <[email protected]>
+
+	* XslKey.cs : Fixed match pattern in xsl:key to check attribute nodes.
+	  To minimize attribute iteration, use Pattern.EvaluatedNodeType.
+	  Fixed bug #75709.
+
 2005-07-29  Atsushi Enomoto  <[email protected]>
 
 	* XslFunctions.cs : XslTransform recovers from errors on document

+ 20 - 2
mcs/class/System.XML/Mono.Xml.Xsl/XslKey.cs

@@ -119,19 +119,37 @@ namespace Mono.Xml.Xsl
 			nav.MoveToRoot ();
 			XPathNavigator tmp = doc.Clone ();
 
+			bool matchesAttributes = false;
+			switch (key.Match.EvaluatedNodeType) {
+			case XPathNodeType.All:
+			case XPathNodeType.Attribute:
+				matchesAttributes = true;
+				break;
+			}
+
 			do {
 				if (key.Match.Matches (nav, ctx)) {
 					tmp.MoveTo (nav);
 					CollectIndex (nav, tmp);
 				}
-			} while (MoveNavigatorToNext (nav));
+			} while (MoveNavigatorToNext (nav, matchesAttributes));
 			if (map != null)
 				foreach (ArrayList list in map.Values)
 					list.Sort (XPathNavigatorComparer.Instance);
 		}
 
-		private bool MoveNavigatorToNext (XPathNavigator nav)
+		private bool MoveNavigatorToNext (XPathNavigator nav, bool matchesAttributes)
 		{
+			if (matchesAttributes) {
+				if (nav.NodeType != XPathNodeType.Attribute &&
+					nav.MoveToFirstAttribute ())
+					return true;
+				else if (nav.NodeType == XPathNodeType.Attribute) {
+					if (nav.MoveToNextAttribute ())
+						return true;
+					nav.MoveToParent ();
+				}
+			}
 			if (nav.MoveToFirstChild ())
 				return true;
 			do {