10

I have the following XML structure:

<root>
  <Level1 IsEnabled="0"> <!-- Disabled -->
    <Level2 IsEnabled="1">
      <Level3 IsEnabled="1">
        <Level4 IsEnabled="1">
          <Child /> <!-- Don't include this one -->
        </Level4>
      </Level3>
    </Level2>
  </Level1>
  <Level1 IsEnabled="1">
    <Level2 IsEnabled="1">
      <Level3 IsEnabled="0"> <!-- Disabled -->
        <Level4 IsEnabled="1">
          <Child /> <!-- Don't include this one -->
        </Level4>
      </Level3>
    </Level2>
  </Level1>
  <Level1 IsEnabled="1">
    <Level2 IsEnabled="1">
      <Level3 IsEnabled="1">
        <Level4 IsEnabled="1">
          <Child /><!-- Include this one -->
        </Level4>
      </Level3>
    </Level2>
   </Level1>
</root>

I want to select all child nodes where any of its ancestors do not contain IsEnabled="0". So for the XML above I only want to select the last child node. In addition, if a ancestor node doesn't contain a IsEnabled attribute, then the child should still be included.

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Matt Ruwe
  • 3,386
  • 6
  • 39
  • 77

1 Answers1

14

Q: I want to select all child nodes where any of its ancestors do not contain IsEnabled="0" Try this:

//Child[not(ancestor::*[@IsEnabled='0'])]
danronmoon
  • 3,814
  • 5
  • 34
  • 56
hr_117
  • 9,589
  • 1
  • 18
  • 23