KeyPattern.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // Mono.Xml.XPath.KeyPattern
  3. //
  4. // Author:
  5. // Ben Maurer ([email protected])
  6. //
  7. // (C) 2003 Ben Maurer
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.IO;
  12. using System.Xml;
  13. using System.Xml.Schema;
  14. using System.Xml.XPath;
  15. using System.Xml.Xsl;
  16. using Mono.Xml.Xsl;
  17. using Mono.Xml.Xsl.Functions;
  18. namespace Mono.Xml.XPath {
  19. internal class KeyPattern : LocationPathPattern {
  20. XmlQualifiedName keyName;
  21. string arg0, arg1;
  22. XsltKey key;
  23. public KeyPattern (XsltKey key)
  24. : base ((NodeTest) null)
  25. {
  26. this.key = key;
  27. ExprLiteral keyName = key.KeyName as ExprLiteral;
  28. ExprLiteral field = key.Field as ExprLiteral;
  29. this.arg0 = keyName.Value;
  30. this.arg1 = field.Value;
  31. this.keyName = XslNameUtil.FromString (arg0, key.NamespaceManager);
  32. }
  33. public override bool Matches (XPathNavigator node, XsltContext ctx)
  34. {
  35. XsltCompiledContext xctx = ctx as XsltCompiledContext;
  36. XslKey xslkey = xctx.Processor.CompiledStyle.Keys [keyName] as XslKey;
  37. XPathNodeIterator iter = key.EvaluateNodeSet (new SelfIterator (node, ctx));
  38. while (iter.MoveNext ())
  39. if (iter.Current.IsSamePosition (node))
  40. return true;
  41. return false;
  42. }
  43. public override double DefaultPriority { get { return 0.5; } }
  44. }
  45. }