This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to access to a node content randomly in xsl:for-each loop


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]