Re: Random node
Mike Brown <[email protected]>
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <[email protected]> |
You could have a node-set consisting of all the nodes you want to choose from, and then multiply 1 less than the size of that set, as obtained by count() or last(), by the random number that's between 0 and 1, rounding down, and then adding 1. This will give you a number between 1 and the size of the set, which you can use as a positional predicate, like this: <xsl:variable name="someNodes" select="/path/to/some/nodes/*"/> <xsl:variable name="randomNode" select="$someNodes[floor(math:random() * (last() -1)) + 1]"/> Untested code but should give you some ideas...