[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: question on random numbers for browser XSLT

Subject: Re: question on random numbers for browser XSLT
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 25 Jul 2009 12:03:49 +0200
Re:  question on random numbers for browser XSLT
Michael Kay wrote:
<xsl:template name="rand">
<xsl:param name="scale" select="6" />
<xsl:variable name="seed" />
<xsl:choose>
<xsl:when test="function-available('exsl:node-set')">
<xsl:value-of select="document(concat('/cgi-bin/rand.pl?', $scale, '&amp;x=', generate-id(exsl:node-set($seed))))" />
</xsl:when>
<xsl:when test="function-available('msxsl:node-set')">
<xsl:value-of select="document(concat('/cgi-bin/rand.pl?', $scale, '&amp;x=', generate-id(msxsl:node-set($seed))))" />
</xsl:when>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>


That'll give you six random values, assuming the Perl script recognizes the &x=Idxxxxx as cache-append garbage.
Interesting approach however when I test it with browsers then Firefox (3.0), Opera (9.63) and Safari (3.2) all seem to generate the same id each time that template is called:
http://home.arcor.de/martin.honnen/xslt/test2009072402.xml
(stylesheet: http://home.arcor.de/martin.honnen/xslt/test2009072402Xsl.xml)


Only IE (tested with IE 8) generates different ids.


In XSLT 1.0 (I was surprised to rediscover just now), the value of variable $seed is not a result tree fragment, it is a zero-length string. So I'm a little bit surprised that exslt:node-set() should work on it at all, and not particularly surprised that it should generate the same node-set each time.

The stylesheet I used for testing (http://home.arcor.de/martin.honnen/xslt/test2009072402Xsl.xml) does create a result tree fragment with some contents in xsl:variable. Otherwise the test case would not have worked at all with some implementations (Opera for instance).





--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.