XPath getting a node back using a max value
<p>Say I have a bunch of elements like this:</p>

<pre><code>&lt;rs&gt;
 &lt;r&gt;
  &lt;roomID&gt;ID2&lt;/roomID&gt;
 &lt;/r&gt;
 &lt;r&gt;
  &lt;roomID&gt;ID2&lt;/roomID&gt;
 &lt;/r&gt;
 &lt;r&gt;
  &lt;roomID&gt;ID3&lt;/roomID&gt;
 &lt;/r&gt;
 &lt;r&gt;
  &lt;roomID&gt;ID2&lt;/roomID&gt;
 &lt;/r&gt;
&lt;/rs&gt;

&lt;rooms&gt;
 &lt;room id="ID1"&gt;
  &lt;val&gt;200&lt;/val&gt;
 &lt;/room&gt;
 &lt;room id="ID2"&gt;
  &lt;val&gt;100&lt;/val&gt;
 &lt;/room&gt;
 &lt;room id="ID3"&gt;
  &lt;val&gt;200&lt;/val&gt;
 &lt;/room&gt;
&lt;/rooms&gt;
</code></pre>

<p>I need to cycle through <code>rs</code>, and find the <code>r</code> that has the highest room value based on the <code>roomID</code>, which would be the third <code>r</code> element here (with roomID=ID3).</p>

<p>If I do this:</p>

<pre><code>&lt;xsl:variable name="max1" select="max(//room[@id=//r/roomID]/val)"/&gt;
</code></pre>

<p>, I get 200, which is correct. But is there any way to get the specific ID back from this? If I just use the max value to get back the ID from the <code>room</code> elements, I can't know if it comes back from the same node. Something like this:</p>

<pre><code>//room[val=max(//room[@id=//r/roomID]/val)]/@id[1]
</code></pre>