Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use xsl:sort to sort images NOT based on position()
    text
    copied!<p><strong>EDITED: ADDITIONAL INFO BELOW</strong></p> <p>I am trying to sort images in ascending order using &lt;<strong>xsl:sort</strong>> without having to use the "<strong>position</strong>() function.</p> <p>I am experiencing an issue using the &lt;<strong>xsl:sort</strong>> function to sort images in ascending order.</p> <p>This is my XML input code that links to the product <strong>ASAMSCM195265783.jpg</strong>:</p> <pre><code> &lt;objectImage code="ASAMSCM195265783" name="NX1000 Compact System Camera in White with 20-50mm Lens Product Image (Primary)" imageTypeName="Product Image" imageTypeCode="PRODUCT" objectTypeImageCode="PRIMARY_PRODUCT" objectTypeImageName="Primary Product Image" displayOrder="7"&gt; &lt;imageVersions&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_SM" width="15" height="15" path="PRODUCT/PRODUCT_THUMB_SM/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_M" width="32" height="32" path="PRODUCT/PRODUCT_THUMB_M/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_REGULAR" width="170" height="170" path="PRODUCT/PRODUCT_REGULAR/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_ENLARGED" width="500" height="500" path="PRODUCT/PRODUCT_ENLARGED/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_L" width="36" height="36" path="PRODUCT/PRODUCT_THUMB_L/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_XL" width="150" height="150" path="PRODUCT/PRODUCT_THUMB_XL/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_110" width="110" height="110" path="PRODUCT/PRODUCT_THUMB_110/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_LARGE" width="300" height="300" path="PRODUCT/PRODUCT_LARGE/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_50x50" width="50" height="50" path="PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783.jpg" link=""/&gt; &lt;imageVersion versionTypeCode="PRODUCT_THUMB_75x75" width="75" height="75" path="PRODUCT/PRODUCT_THUMB_75x75/ASAMSCM195265783.jpg" link=""/&gt; &lt;/imageVersions&gt; &lt;/objectImage&gt; </code></pre> <p>My other XML examples for the other <strong>ASAMSCM195265783.jpg</strong> products are exactly the same as above but only differences are that <strong>objectTypeImageCode="OTHER_PRODUCT"</strong> instead of <strong>PRIMARY_PRODUCT</strong> and the <strong>displayOrder="8"</strong> and <strong>"9"</strong>.</p> <p>This is my current XSLT code:</p> <pre><code>&lt;xsl:sort select="displayOrder" data-type="number" order="descending"/&gt; &lt;li class="prodthumbimg"&gt; &lt;a&gt; &lt;xsl:attribute name="id"&gt; &lt;xsl:text&gt;thumb&lt;/xsl:text&gt; &lt;xsl:value-of select="position()" /&gt; </code></pre> <p>Here is the result in HTML:</p> <pre><code>&lt;li class="prodthumbimg"&gt;&lt;a id="thumb10" href="javascript:void(swap(9));" target=""&gt;&lt;img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_009.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="prodthumbimg"&gt;&lt;a id="thumb9" href="javascript:void(swap(8));" target=""&gt;&lt;img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="prodthumbimg"&gt;&lt;a id="thumb8" href="javascript:void(swap(7));" target=""&gt;&lt;img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_008.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"&gt;&lt;/a&gt;&lt;/li&gt; </code></pre> <p>Notice in the second line of my HTML result the product image <strong>ASAMSCM195265783.jpg</strong> is in the wrong place? I am trying to display that image in the third line of my HTML result. So basically the 2nd and 3rd html line needs to be swapped around so that the name of the product images can be sorted out properly in descending order.</p> <p>Whenenver I use:</p> <pre><code>&lt;xsl:sort select="position()" data-type="number" order="descending"/&gt; &lt;li class="prodthumbimg"&gt; &lt;a&gt; &lt;xsl:attribute name="id"&gt; &lt;xsl:text&gt;thumb&lt;/xsl:text&gt; &lt;xsl:value-of select="position()" /&gt; </code></pre> <p>It does the job but only based on <strong>position()</strong> (the number of the product), I am trying do this based on the product name not the number within the product name (if that makes sense). Any help would be appreciated, thanks in advance (if you need further clarification or any further questions please let me </p> <p>This is my desired result in HTML:</p> <pre><code>&lt;li class="prodthumbimg"&gt;&lt;a id="thumb10" href="javascript:void(swap(9));" target=""&gt;&lt;img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_009.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="prodthumbimg"&gt;&lt;a id="thumb9" href="javascript:void(swap(8));" target=""&gt;&lt;img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783_008.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="prodthumbimg"&gt;&lt;a id="thumb8" href="javascript:void(swap(7));" target=""&gt;&lt;img src="http://www.jessops.com/ce-images/PRODUCT/PRODUCT_THUMB_50x50/ASAMSCM195265783.jpg" alt="Samsung NX1000 Compact System Camera in White with 20-50mm Lens" title="Samsung NX1000 Compact System Camera in White with 20-50mm Lens"&gt;&lt;/a&gt;&lt;/li&gt; </code></pre> <p>If there are anymore additional info that you would think is more relevant to post here to clarify further this issue please let me know, thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload