I have been going crazy to find out a way to display a random node (banner item). I have done alot of tips and tricks from the forum but the working ones wont work in medium trust.
I have also tried to create a xslt extension to get a random number, but the <xsl:sort> wont work when doing so anyway.
Have someone found a way to display a random item in medium trust?
Do you only need one random item? Or a whole list of random items?
If only one you could do it in a couple of ways with an xslt extension. One is to generate a random number with max number equal to the total count, then you can use an if statement to check position() = your random number, if true render the item. Another way to do it is send in all ids of the banner nodes to the xslt extension, make a random function to return the id of the random node, and then use xslt to return it.
If you need a list of random items you propberly need to look into an xslt extension returning a nodeset using nodefactory.
This is a banner system and I would like the administrator to choose how many banners to display, and IF they will be in a random order or not. So I guess your third suggestion by using nodefactory would do it.
Would it on the other hand be better to create a usercontrol for this? Or is an xslt extension the best way? I'm thinking it maybe is a good idea to cache the macro for a faster experience ?
xslt extensions are very very powerfull. You could perhaps make it a bit generic so you can use it for other random functions also. You might want to consider to use the nodeset of all "your" banner items as an in parameter, and then use .net to random the nodeset and return it back. Hopefully you understand what I mean.
Yeah, I understand what you mean. Never used extensions with nodesets before, but I know there's a how-to video about this on umbraco.org. I'll check that out.. Thank you for your help :)
Display random node in medium trust
Hi all..
I have been going crazy to find out a way to display a random node (banner item). I have done alot of tips and tricks from the forum but the working ones wont work in medium trust.
I have also tried to create a xslt extension to get a random number, but the <xsl:sort> wont work when doing so anyway.
Have someone found a way to display a random item in medium trust?
Hi Dekline,
Haven´t tested it, but maybe this will work for you: http://blogs.thesitedoctor.co.uk/tim/CommentView,guid,1f190396-eaf7-49a2-a3f0-3873df4a0ccd.aspx
Regards, Martin
Hi Martin
The thing is that i'm not allowed to run
<msxml:script language="JavaScript" implements-prefix="math"></msxml:script>
in medium trust. But could I create some sort of xslt extension that i will be able to <xsl:sort> with?
Hi,
Ok, now I see. I have no other solution, sorry...
Do you only need one random item? Or a whole list of random items?
If only one you could do it in a couple of ways with an xslt extension. One is to generate a random number with max number equal to the total count, then you can use an if statement to check position() = your random number, if true render the item. Another way to do it is send in all ids of the banner nodes to the xslt extension, make a random function to return the id of the random node, and then use xslt to return it.
If you need a list of random items you propberly need to look into an xslt extension returning a nodeset using nodefactory.
Hi there Anders
This is a banner system and I would like the administrator to choose how many banners to display, and IF they will be in a random order or not. So I guess your third suggestion by using nodefactory would do it.
Would it on the other hand be better to create a usercontrol for this? Or is an xslt extension the best way? I'm thinking it maybe is a good idea to cache the macro for a faster experience ?
xslt extensions are very very powerfull. You could perhaps make it a bit generic so you can use it for other random functions also. You might want to consider to use the nodeset of all "your" banner items as an in parameter, and then use .net to random the nodeset and return it back. Hopefully you understand what I mean.
Yeah, I understand what you mean. Never used extensions with nodesets before, but I know there's a how-to video about this on umbraco.org. I'll check that out.. Thank you for your help :)
is working on a reply...