Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RANDOM NUMBER

Status
Not open for further replies.

rjonesX

Technical User
Jun 18, 2001
56
US
I need to generate a random number inside my xsl script that will be written into a form field. javascript document.write stuff doesnt work. any ideas?

russ
 
yep..

you would have to extend xpath functions to generate a random number.. something like this:

<xsl:stylesheet version=&quot;1.0&quot; xmlns:inatos=&quot;uri://none&quot; xmlns:xsl=&quot; xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot;>

<msxsl:script language=&quot;JavaScript&quot; implements-prefix=&quot;inatos&quot;>
<![CDATA[
function rand()
{
return &quot;&quot; + Math.random();
}
]]>
</msxsl:script>

<xsl:template match=&quot;/&quot;>
<xsl:value-of select=&quot;inatos:rand()&quot;/>
</xsl:template>
</xsl:stylesheet>

Heres something to do too, try to make the function take an argument from a node value , and seed the random number :) Hint: you are passing a node to the function, and therefore have to treat it like a node, not an int!

This only works with MSXML, and you would have to find other ways of doing with other engines...

There are some good pre-made packages to do this sort of thing for other engines at
Hope that points you in the right direction...!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top