[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: Fri, 24 Jul 2009 19:28:16 +0200
|
Hermann Stamm-Wilbrandt wrote:
Scott Trenda has problems in getting his email accepted by xsl-list and
asked me to forward his response to Ben's post.
[snip]
The cache-append idea was my first thought, but I couldn't think of a good
way to pull together how to have each request be unique. It's possible
using node-set(), though:
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="exsl
msxsl">
<xsl:output method="html" encoding="UTF-8" />
<xsl:template match="/">
<html>
<body>
<div>rand(6): <xsl:call-template name="rand" /></div>
<div>rand(6): <xsl:call-template name="rand" /></div>
<div>rand(6): <xsl:call-template name="rand" /></div>
<div>rand(6): <xsl:call-template name="rand" /></div>
<div>rand(6): <xsl:call-template name="rand" /></div>
<div>rand(6): <xsl:call-template name="rand" /></div>
</body>
</html>
</xsl:template>
<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,
'&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,
'&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.
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|