title: XPath Selecting Nodes Until Condition
body: <p>I have a HTML/XML document similar to the following. There can be one or more 'tr' of the same colour before switching to the other colour in an arbitrarily repeating pattern. This is an example:</p>
  
  <pre><code>&lt;tr class='red'&gt;&lt;/tr&gt;
  &lt;tr class='blue'&gt;&lt;/tr&gt;
  &lt;tr class='red'&gt;&lt;/tr&gt;
  &lt;tr class='red'&gt;&lt;/tr&gt;
  &lt;tr class='red'&gt;&lt;/tr&gt;
  &lt;tr class='blue'&gt;&lt;/tr&gt;
  &lt;tr class='blue'&gt;&lt;/tr&gt;
  &lt;tr class='red'&gt;&lt;/tr&gt;
  &lt;tr class='red'&gt;&lt;/tr&gt;
  &lt;tr class='blue'&gt;&lt;/tr&gt;
  </code></pre>
  
  <p>What I am looking for is an XPath (1.0) expression which, starting from the first 'tr' in any colour 'block' (note that there is <strong>no</strong> markup indicating these blocks, only alterations in the colour), selects the following subsequent 'tr's within that block only.</p>
  
  <p>I have tried the following expression</p>
  
  <pre><code>./following-sibling::tr[@class=preceding-sibling::tr[1]/@class]
  </code></pre>
  
  <p>but this also selects the second+ 'tr's of subsequent blocks. I feel like I'm close to what I need, but can't quite manage it.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit: The desired output is a nodeset containing the subsequent 'tr's within the block (and only that block).</p>