I have a configuration file in xml, with increasing specificity. That is, the closest setting to some section is the setting that will be in effect, even if it is set on higher levels. A colleague suggested using XPath for this. But I'm not sure how it would work? I suppose I want to find the "deepest match" for the setting, then automatically backing out if there is no match.

For instance:

```
<Settings>
 <Foo>Bar</Foo>
 <Products>
  <Bar>Baz</Bar>
  <Product Name="Thingamabob">
   <Foo>Baz</Foo>
  </Product>
  <Product Name="Whizbang">
   <Bar>Foo</Bar>
  </Product>
 </Products>
</Settings>

```

Searching for the `Bar` setting for Thingamabob should return "Baz", but "Foo" on Whizbang. In the same way, `Foo` has a value of "Baz" for Thingamabob, but "Bar" on Whizbang.

Can this type of lookup be implemented with XPath?