def HasParent(s1, s2):
  """ HasParent(s1, s2) returns a selector that selects a node, n, only if
        * s1 selects the node, n
        * s2 selects the parent of the node, n.parent."""
  def MatchNode(x):
    if not s1(x):
      return False

    n = x.GetParent()

    if n is not None:
      return s2(n)

  return MatchNode