would someone please give me some guidance of how to achieve such thing. i've tried to create a variable $sortlist, and then add delimited character around and then use substring-before trick on the sort. result is my sorted list did show up on top before the rest of the movies but it's not on the right order. please help.
Yeah - you need to pull a different trick out of the bag for this to work... something like this:
<!-- Grab the movies - change to suit your data -->
<xsl:variable name="movies" select="$currentPage/movieList/movie" />
<!-- $movieSort is the <movies>xxx,yyy,zzz</movies> from somewhere -->
<xsl:variable name="promoted" select="umbraco.library:Split($movieSort/movies, ',')//value" />
<xsl:template match="/">
<xsl:apply-templates select="$movies">
<!-- First sort puts "promoted" elements at the top -->
<xsl:sort select="number(boolean($promoted[. = current()]))" data-type="number" order="descending" />
<!-- Second sort puts them in the correct order by -->
<xsl:sort select="count($promoted[. = current()] | $promoted[. = current()]/preceding-sibling::*)" data-type="number" order="ascending" />
</xsl:apply-templates>
</xsl:template>
<!-- Sample output template for each movie -->
<xsl:template match="movie">
<p><xsl:value-of select="." /></p>
</xsl:template>
Thank you for your quick reply. Would you mind revise your example in different form by using <xsl:for-each> and <xsl:sort> ? The big movie list is current stuck in a massive <xsl:sort> order where I'm not sure if it's a good idea to break it down into small apply-template methods. Sorry if it's a newbie request. Also, if you had any reasons why you chose to normalize the whole deal in several <xsl:template>, please explain, i'd love to hear/learn from the expert :) Once again, thanks!
So, in a simple scenario you may like the for-each better, but the power of apply-templates comes in as soon as the "A" doesn't relate to only one piece of information, but many different.
Adding another type (e.g. a TVSeries or ThreeDMovie) to the collection which should use the same sorting logic, but render in a slightly different way, is as simple as making sure it's selected in the apply-templates' select attribute and then adding specific templates for them.
In a for-each construct, you'd have to use a set of choose/when or if statements to do the different renderings...
sort a list from an order of a different list
i have a sort order list of movies (order from left to right)
now i want to take that sort order list and sort on top of this huge movies list of mine
result i want:
would someone please give me some guidance of how to achieve such thing. i've tried to create a variable $sortlist, and then add delimited character around and then use substring-before trick on the sort. result is my sorted list did show up on top before the rest of the movies but it's not on the right order. please help.
Hi,
Have a look at this threat where Chriztian AKA Mr XSLT explains how to achieve this
Hope this will help you
i dont see nor understand how using translate() will help my situation, would you mind explain ?
Hi bev0,
Yeah - you need to pull a different trick out of the bag for this to work... something like this:
/Chriztian
Hi Chriztian,
Thank you for your quick reply. Would you mind revise your example in different form by using <xsl:for-each> and <xsl:sort> ? The big movie list is current stuck in a massive <xsl:sort> order where I'm not sure if it's a good idea to break it down into small apply-template methods. Sorry if it's a newbie request. Also, if you had any reasons why you chose to normalize the whole deal in several <xsl:template>, please explain, i'd love to hear/learn from the expert :) Once again, thanks!
Hi bev0,
OK - here's how the two methods relate:
Using for-each:
Using apply-templates:
/Chriztian
thank you for your detail explanation, Chriztian. i learnt a thing or two after reading your comments :)
is working on a reply...