INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

XPATH

How do I generate random numbers with XPATH? by flumpy
Posted: 21 May 02

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

<xsl:stylesheet version="1.0" xmlns:inatos="uri://none" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";; xmlns:msxsl="urn:schemas- microsoft-com:xslt">

    <msxsl:script language="JavaScript" implements-prefix="inatos">
        <![CDATA[
        function rand()
        {
             return "" + Math.random();
         }
        ]]>
    </msxsl:script>
    
    <xsl:template match="/">
        <xsl:value-of select="inatos:rand()"/>
    </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 http://www.exslt.org/math/

Back to XML FAQ Index
Back to XML Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close