Hmmm... well I don't know if it will do the trick... i don't get very much from the link...
I have now installed the uComponents package...
I can see in the link you posted that theres a RandomNode and RandomChildNode. Unfortunately i'm no coder and have no clue on where to begin. a hint on how this uComponents works?...
Ok, from looking at your code, now not sure if I understood very well... you do want to have a random node choosen amonst the child nodes of the $source node, right? If that's the case, this is what to do;
Have to make sure the xslt extension is *known* by the umbraco system. Either the uComponents installer has asked you whether and what xslt extensions to install (I even think you can still add it when going to the /installed packages node in the developer section), or you can configure manually as found on the page I've sent the link for.
Once that's configured, you can use any xslt extension method defined in that assembly, so in your case, you could write:
<xsl:variable name="randomNode" select="ucomponents.xml:RandomNode(umbraco.library:GetXmlNodeById($source))/*[@isDoc and string(umbracoNaviHide! = '1' and string(billede) != ''])" />
which will return a single random node that has a property billede which has a value (probably a media picker)
Ah, afraid such an xslt extension doens't exist atm... Might want to add that as a feature request on the uComponents Codeplex page. Doesn't help you out right now. Any case, it will require some c# coding, either by you or the uComponents team...
Based on various experiments, you could try the following sort expression...
<xsl:sort select="position() mod Exslt.ExsltMath:random()" order="descending"/>
The key part here is including a reference to the "Exslt.ExsltMath" extensions and calling the "random()" function. The beauty of this approach is that the modulus for each position against the random number will be unique - so you could base a dynamic sort on that.
Like Dirk also a big thank you for taking the time to help out...
Before I get my hands "dirty" in code... The "Exslt.ExsltMath" is that part of the uComponents package and if yes what extension(s) do i need to install?
And yes I do worry about the kittens... all this code is just mock-up and will be replaced by css later :)
Randomize Xslt list
Hi there...
Is there a simple way to randomize the list items of a Xslt generated ul?
I have the following code
<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']">
<xsl:if test="billede != ''">
<xsl:variable name="myPic" select="umbraco.library:GetMedia(billede,'false')/umbracoFile" />
<li class="s3sliderImage">
<a href="{umbraco.library:NiceUrl(@id)}" ><img src="{concat(substring-before($myPic,'.'),'_FrontSlide.',substring-after($myPic,'.'))}" border="0" alt="{@nodeName}"/></a>
<span><xsl:value-of select="@nodeName"/>: <xsl:value-of select="vejlPris"/> kun kr. <font color="#ff0000" size="6" align="right"><xsl:value-of select="pris"/></font></span>
</li>
</xsl:if>
</xsl:for-each>
<div></div>
</ul>
Could this be something you're after? Requires you to install uComponents package as it will contain the required assembly to run the xslt extension
Cheers,
/Dirk
Hi Dirk
Thx for your time!...
Hmmm... well I don't know if it will do the trick... i don't get very much from the link...
I have now installed the uComponents package...
I can see in the link you posted that theres a RandomNode and RandomChildNode. Unfortunately i'm no coder and have no clue on where to begin. a hint on how this uComponents works?...
Cheers Crawn
Ok, from looking at your code, now not sure if I understood very well... you do want to have a random node choosen amonst the child nodes of the $source node, right? If that's the case, this is what to do;
Have to make sure the xslt extension is *known* by the umbraco system. Either the uComponents installer has asked you whether and what xslt extensions to install (I even think you can still add it when going to the /installed packages node in the developer section), or you can configure manually as found on the page I've sent the link for.
Once that's configured, you can use any xslt extension method defined in that assembly, so in your case, you could write:
<xsl:variable name="randomNode" select="ucomponents.xml:RandomNode(umbraco.library:GetXmlNodeById($source))/*[@isDoc and string(umbracoNaviHide! = '1' and string(billede) != ''])" />
which will return a single random node that has a property billede which has a value (probably a media picker)
Hope this helps.
Regards,
/Dirk
Hi Dirk
My code lists subpages from a page..
<ul>
<li> - Subpage 1 </li>
<li> - Subpage 2 </li>
<li> - Subpage 3 </li>
</ul>
...and it is that list i wanna randomize
<ul>
<li> - Subpage 2 </li>
<li> - Subpage 3 </li>
<li> - Subpage 1 </li>
</ul>
Cheers
Crawn
Ah, afraid such an xslt extension doens't exist atm... Might want to add that as a feature request on the uComponents Codeplex page. Doesn't help you out right now. Any case, it will require some c# coding, either by you or the uComponents team...
Cheers,
/Dirk
Hi Crawn,
Based on various experiments, you could try the following sort expression...
The key part here is including a reference to the "Exslt.ExsltMath" extensions and calling the "random()" function. The beauty of this approach is that the modulus for each position against the random number will be unique - so you could base a dynamic sort on that.
Here's a full snippet:
Good luck!
Cheers, Lee.
PS. Please don't use <font> tags, think about the kittens!
Hi Lee
Like Dirk also a big thank you for taking the time to help out...
Before I get my hands "dirty" in code... The "Exslt.ExsltMath" is that part of the uComponents package and if yes what extension(s) do i need to install?
And yes I do worry about the kittens... all this code is just mock-up and will be replaced by css later :)
Cheers, Crawn
"Exslt.ExsltMath" is part of Umbraco core... it is usually included on any new XSLT files that are created via the back-office.
Cheers, Lee.
All I can say... Umbraco kicks ass!...
Thanks Lee! That did the trick. The list is now random each time the page is loaded :)
Think I will go save some kittens now ;)
Cheers and Merry Christmas ...I can say this because it's december now! :)
/Crawn
Holy crap Lee Keller. I've been looking for a way to randomly sort for days. using
<xsl:sort select="floor( Exslt.ExsltMath:random()* $itemCount)" />
and tearing my hair out because random is based off the clock, thus they would all be showing up as the same item.
using mod is ingenious. I have been googling for days. This needs to be made more prominent!
is working on a reply...