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. namespace Mono.Xml.XPath
  18. {
  19. internal class KeyPattern : LocationPathPattern
  20. {
  21. XmlQualifiedName keyName;
  22. string arg0, arg1;
  23. XsltKey key;
  24. public KeyPattern (XsltKey key)
  25. : base ((NodeTest) null)
  26. {
  27. this.key = key;
  28. ExprLiteral keyName = key.KeyName as ExprLiteral;
  29. ExprLiteral field = key.Field as ExprLiteral;
  30. this.arg0 = keyName.Value;
  31. this.arg1 = field.Value;
  32. this.keyName = XslNameUtil.FromString (arg0, key.NamespaceManager);
  33. }
  34. public override bool Matches (XPathNavigator node, XsltContext ctx)
  35. {
  36. XsltCompiledContext xctx = ctx as XsltCompiledContext;
  37. XslKey xslkey = xctx.Processor.CompiledStyle.Keys [keyName] as XslKey;
  38. XPathNodeIterator iter = key.EvaluateNodeSet (new SelfIterator (node, ctx));
  39. while (iter.MoveNext ())
  40. if (iter.Current.IsSamePosition (node))
  41. return true;
  42. return false;
  43. }
  44. public override double DefaultPriority { get { return 0.5; } }
  45. }
  46. }