XSLT2: How to match a single node based on priority
<p>I need to make a new xml structure where only one image-version exist, and that should be the version that is either "a", "16x9s" or "4x3s" - in that priority. So if an image version "a" exist, then only that image is chosen. if it doesn't then look for "16x9s" and finally "4x3s". 
Also needed are a few other nodes(in caps in the wanted result code below), while all the other nodes should be discarded.</p>

<p><strong>The xml (an excerpt, it can be a lot longer or shorter):</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
&lt;io&gt;
    &lt;publication id="106125"/&gt;
    &lt;related-images&gt;
        &lt;image id="1112835"&gt;
            &lt;caption&gt;null&lt;/caption&gt;
            &lt;placement&gt;FRONTPAGETITLE&lt;/placement&gt;
            &lt;alignment&gt;left&lt;/alignment&gt;
            &lt;photographer&gt;&lt;/photographer&gt;
            &lt;credit&gt;&lt;/credit&gt;
            &lt;name&gt;Some text&lt;/name&gt;
            &lt;author&gt;&lt;/author&gt;
            &lt;copyright&gt;&lt;/copyright&gt;
            &lt;path&gt;Image Root&lt;/path&gt;
            &lt;description&gt;&lt;/description&gt;
            &lt;alt-text&gt;&lt;/alt-text&gt;
            &lt;image-version version-id="2060510" version-type="16x9s"&gt;
                &lt;url&gt;/archive/01112/Thomas-Hicks-1_111283516x9s.jpg&lt;/url&gt;
                &lt;width&gt;649&lt;/width&gt;
                &lt;height&gt;365&lt;/height&gt;
            &lt;/image-version&gt;
            &lt;image-version version-id="2060512" version-type="a"&gt;
                &lt;url&gt;/archive/01112/Thomas-Hicks-16_11128353x4s.jpg&lt;/url&gt;
                &lt;width&gt;413&lt;/width&gt;
                &lt;height&gt;550&lt;/height&gt;
            &lt;/image-version&gt;
            &lt;image-version version-id="2060513" version-type="4x3s"&gt;
                &lt;url&gt;/archive/01112/Thomas-Hicks-16_11128354x3s.jpg&lt;/url&gt;
                &lt;width&gt;550&lt;/width&gt;
                &lt;height&gt;413&lt;/height&gt;
            &lt;/image-version&gt;
        &lt;/image&gt;
        &lt;image id="1111482"&gt;
            &lt;caption&gt;Some text&lt;/caption&gt;
            &lt;placement&gt;FRONTPAGELEADTEXT&lt;/placement&gt;
            &lt;alignment&gt;left&lt;/alignment&gt;
            &lt;photographer&gt;&lt;/photographer&gt;
            &lt;credit&gt;&lt;/credit&gt;
            &lt;name&gt;Some text&lt;/name&gt;
            &lt;author&gt;&lt;/author&gt;
            &lt;copyright&gt;&lt;/copyright&gt;
            &lt;path&gt;Image Root&lt;/path&gt;
            &lt;description&gt;&lt;/description&gt;
            &lt;alt-text&gt;&lt;/alt-text&gt;
            &lt;image-version version-id="2060099" version-type="4x3s"&gt;
                &lt;url&gt;/archive/01111/1904_tugofwar_11114824x3s.jpg&lt;/url&gt;
                &lt;width&gt;640&lt;/width&gt;
                &lt;height&gt;363&lt;/height&gt;
            &lt;/image-version&gt;
            &lt;image-version version-id="2060075" version-type="f-tn"&gt;
                &lt;url&gt;/archive/01111/1904_tugofwar_1111482f-tn.jpg&lt;/url&gt;
                &lt;width&gt;200&lt;/width&gt;
                &lt;height&gt;113&lt;/height&gt;
            &lt;/image-version&gt;
            &lt;image-version version-id="2060094" version-type="y"&gt;
                &lt;url&gt;/archive/01111/1904_tugofwar_1111482y.jpg&lt;/url&gt;
                &lt;width&gt;484&lt;/width&gt;
                &lt;height&gt;274&lt;/height&gt;
            &lt;/image-version&gt;
        &lt;/image&gt;
        &lt;image id="1111465"&gt;
            &lt;caption&gt;Some text&lt;/caption&gt;
            &lt;placement&gt;FRONTPAGELEADTEXT&lt;/placement&gt;
            &lt;alignment&gt;left&lt;/alignment&gt;
            &lt;photographer&gt;Getty Images&lt;/photographer&gt;
            &lt;credit&gt;&lt;/credit&gt;
            &lt;name&gt;Some text&lt;/name&gt;
            &lt;author&gt;&lt;/author&gt;
            &lt;copyright&gt;&lt;/copyright&gt;
            &lt;path&gt;Image Root&lt;/path&gt;
            &lt;description&gt;&lt;/description&gt;
            &lt;alt-text&gt;&lt;/alt-text&gt;
            &lt;image-version version-id="2058398" version-type="a"&gt;
                &lt;url&gt;/archive/01111/1896_1111465a.jpg&lt;/url&gt;
                &lt;width&gt;1499&lt;/width&gt;
                &lt;height&gt;1103&lt;/height&gt;
            &lt;/image-version&gt;
        &lt;/image&gt;
    &lt;/related-images&gt;
&lt;/io&gt;
</code></pre>

<p><strong>The wanted result:</strong></p>

<pre><code>&lt;PTR:image&gt;
    &lt;PTR:width&gt;WIDTH OF IMAGE&lt;/PTR:width&gt;
    &lt;PTR:height&gt;HEIGHT OF IMAGE&lt;/PTR:height&gt;

    &lt;PTR:src&gt;IMAGE URL&lt;/PTR:src&gt;

    &lt;PTR:title&gt;
        NAME
    &lt;/PTR:title&gt;

    &lt;PTR:description&gt;
        CAPTION
    &lt;/PTR:description&gt;

    &lt;PTR:author&gt;
        PHOTOGRAPHER
    &lt;/PTR:author&gt;
&lt;/PTR:image&gt;
</code></pre>

<p>I've tried a few things, like xsl:when, but my skill level is not good enough yet to make it work. Any help would be greatly appreciated. 
Cheers.</p>