xsl-list
[Top] [All Lists]

Re: Re: Re: Selecting a random node from source-tree

2002-09-26 11:37:01
Oh boy I was blind. Thanks for opening my eyes on this:

I cannot pass parameters. That would have made things fairly easy because I
could have generated a random number outside the transformation.

But -- using any number from the source doc as a seed was the clou. There
will be one number in my source doc, that increments every time I run the
transformation. That'll do!

Unfortunately I may have to drop the FXSL stuff, due to performance and
maintainability. I want to distribute a single XSLT file, which must be kept
as simple as possible. XSLT beginners must be able to apply changes
themselves. *sigh* Your random.xsl is fairly complex. However: using that
incrementing number plus mod will do the trick in this case.


Thanks for the inspiration!


Martin Lormes



I was thinking of an XPath expression like this:

document('funnies.xml')/funnies/quote[random()]

Can I avoid using extension elements?

Yes, use the "randNext" template from FXSL.

More information is contained in the article:

"Casting the Dice with FXSL: Random Number Generation Functions in
XSLT"

http://fxsl.sourceforge.net
/articles/Random/Casting%20the%20Dice%20with%20FXSL-htm.htm

Hope this helped.


Thanks, Dimitre. Awsome article!

Unfortunately I always get the same random number (which makes
perfect
sense, since I can't dynamically generate a starting number :-( )

So I must add this as a condition to my original question: the
stylesheet is
static. No way of changing that.


Thanks for your help.
Martin Lormes


That's easy -- have the minutes or seconds part of the current time (or
whatever else you find appropriate) passed as a parameter to the
stylesheet and use that as the seed (or use a subsequence of the
original sequence, starting with the element having index equal to this
parameter.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list