This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to access to a node content randomly in xsl:for-each loop
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Uslu, Cihan Y (MED)" <Cihan dot Uslu at med dot ge dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Sat, 16 Feb 2002 08:06:58 +0000
- Subject: Re: [xsl] How to access to a node content randomly in xsl:for-each loop
- Organization: Jeni Tennison Consulting Ltd
- References: <411301487662D411ADDB0090274F3A75054F4389@uswaumsx01medge.med.ge.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Cihan,
> I m trying to access the content of a node in random order each time
> when I run the XSL script, is it possible?
XPath doesn't have a random() function, so it isn't possible without
using an extension function. Your processor probably has facilities
for either writing your own extension functions or using Java methods
that would enable you to get hold of a random number. You could then
use that random number to access a single node. Read your processor's
documentation to find out what's available for you.
Once you've created a random() function (I'll call it math:random()),
you can get hold of all the answer elements in a random order by
sorting them based on random numbers with:
<xsl:for-each select="answer">
<xsl:sort select="math:random()" />
...
</xsl:for-each>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list