 <p><strong>Use</strong>:</p> <pre><code>/*/Result/*/Flight [count(*/*)=count(/*/Request/*/FlightId) and not(*/*/FlightNumber[not(. = /*/Request/*/FlightId)]) ] </code></pre> <p><strong>Here is the complete transformation:</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="vHits" select= "/*/Result/*/Flight [count(*/*)=count(/*/Request/*/FlightId) and not(*/*/FlightNumber[not(. = /*/Request/*/FlightId)]) ]"/&gt; &lt;FilterResult&gt; &lt;ResultCount&gt;&lt;xsl:value-of select="count($vHits)"/&gt;&lt;/ResultCount&gt; &lt;Response&gt; &lt;xsl:copy-of select="$vHits"/&gt; &lt;/Response&gt; &lt;/FilterResult&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When this transformation is applied on the provided XML document:</strong></p> <pre><code>&lt;Response&gt; &lt;Request&gt; &lt;RequestedFlights&gt; &lt;FlightId&gt;2121&lt;/FlightId&gt; &lt;FlightId&gt;2584&lt;/FlightId&gt; &lt;/RequestedFlights&gt; &lt;/Request&gt; &lt;Result&gt; &lt;Flights&gt; &lt;Flight&gt; &lt;Segments&gt; &lt;Segment&gt; &lt;Id&gt;1&lt;/Id&gt; &lt;FlightNumber&gt;2121&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;Segment&gt; &lt;Id&gt;2&lt;/Id&gt; &lt;FlightNumber&gt;1121&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;/Segments&gt; &lt;/Flight&gt; &lt;Flight&gt; &lt;Segments&gt; &lt;Segment&gt; &lt;Id&gt;3&lt;/Id&gt; &lt;FlightNumber&gt;2121&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;Segment&gt; &lt;Id&gt;4&lt;/Id&gt; &lt;FlightNumber&gt;2584&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;/Segments&gt; &lt;/Flight&gt; &lt;Flight&gt; &lt;Segments&gt; &lt;Segment&gt; &lt;Id&gt;5&lt;/Id&gt; &lt;FlightNumber&gt;2121&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;Segment&gt; &lt;Id&gt;6&lt;/Id&gt; &lt;FlightNumber&gt;2584&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;Segment&gt; &lt;Id&gt;7&lt;/Id&gt; &lt;FlightNumber&gt;2023&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;/Segments&gt; &lt;/Flight&gt; &lt;/Flights&gt; &lt;/Result&gt; &lt;/Response&gt; </code></pre> <p><strong>the wanted, correct result is produced:</strong></p> <pre><code>&lt;FilterResult&gt; &lt;ResultCount&gt;1&lt;/ResultCount&gt; &lt;Response&gt; &lt;Flight&gt; &lt;Segments&gt; &lt;Segment&gt; &lt;Id&gt;3&lt;/Id&gt; &lt;FlightNumber&gt;2121&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;Segment&gt; &lt;Id&gt;4&lt;/Id&gt; &lt;FlightNumber&gt;2584&lt;/FlightNumber&gt; &lt;/Segment&gt; &lt;/Segments&gt; &lt;/Flight&gt; &lt;/Response&gt; &lt;/FilterResult&gt; </code></pre> <p><strong>Explanation</strong>:</p> <p>Proper use of the <strong><a href="http://en.wikipedia.org/wiki/Double_negation" rel="nofollow">double negation</a></strong> law.</p>