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

Re: Re: question on random numbers for browser XSLT

Subject: Re: Re: question on random numbers for browser XSLT
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 25 Jul 2009 07:32:34 -0700
Re:  Re: question on random numbers for browser XSLT
On Sat, Jul 25, 2009 at 2:05 AM, Hermann
Stamm-Wilbrandt<STAMMW@xxxxxxxxxx> wrote:
>> Or, for XSLT 1.0 one could write the following (knowing that the
>> values contain only uppercase latin characters or digits):
>
> You cannot assume that in general. Here is what IDs get generated
> for different browser/OS when clicking on this link:
> http://www.stamm-wilbrandt.de/en/xsl-list/random/scott.xml
>
> Linux:
> id0x098f7528 B Firefox 3.0.10
> o770813095 B  B Opera 9.64
> IDACI52B B  B  B Internet Explorer 6.0.2800 (ies4linux)
>
> Windows:
> id0x0b563640 B Firefox 3.0.12
> IDACAYFC B  B  B Internet Explorer 6.0.2900
> o5002021 B  B  B Opera 9.63
> id2010145 B  B  Safari 4.0.2
> id205096 B  B  B Chrome 2.0.172


So, just add the lower-case characters to $vChars or translate the id
to upper case in the definition of $vNumericalVal.



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play

>
>
> $ cat scott.xml
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type="text/xsl" href="scott.xsl"?>)
> <tag/>
> $ cat scott.xsl
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> B xmlns:exsl="http://exslt.org/common"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt"
> B exclude-result-prefixes="exsl msxsl"
>>
> B <xsl:output method="html" encoding="UTF-8" />
>
> B <msxsl:script language="JScript" implements-prefix="exsl">
> B  B this['node-set'] = B function (x) {
> B  B  B return x;
> B  B }
> B </msxsl:script>
>
> B <xsl:template match="/">
> B  B <html>
> B  B  B <body>
> B  B  B  B <xsl:variable name="seed"><a/></xsl:variable>
> B  B  B  B <xsl:value-of select="generate-id(exsl:node-set($seed))" />
> B  B  B </body>
> B  B </html>
> B </xsl:template>
>
> </xsl:stylesheet>
>
>
>
> Mit besten GrC<Cen / Best wishes,
>
> Hermann Stamm-Wilbrandt
> Developer, XML Compiler
> WebSphere DataPower SOA Appliances
> ----------------------------------------------------------------------
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Martin Jetter
> GeschC$ftsfC<hrung: Erich Baier
> Sitz der Gesellschaft: BC6blingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294
>
>
>
> B  B  B  B  B  B  Dimitre Novatchev
> B  B  B  B  B  B  <dnovatchev@gmail
> B  B  B  B  B  B  .com> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
B  B  B  B  B  B  B  B  B  B To
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> B  B  B  B  B  B  07/25/2009 01:51 B  B  B  B  B  B  B  B  B  B  B  B  B  B 
B  B  B  B  B  B  B  cc
> B  B  B  B  B  B  AM
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
B  B  B  B  B  B  B  B  Subject
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  Re:  Re:
question on random
> B  B  B  B  B  B  Please respond to B  B  B  B  numbers for browser XSLT
> B  B  B  B  B  B  xsl-list@xxxxxxxx
> B  B  B  B  B  B  B lberrytech.com
>
>
>
>
>
>
>
>
> Or, for XSLT 1.0 one could write the following (knowing that the
> values contain only uppercase latin characters or digits):
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:testmap="testmap"
> exclude-result-prefixes="xsl testmap"
>>
> B  <xsl:import href="str-dvc-map.xsl"/>
>
> B  <!-- to be applied on any xml source -->
>
> B  <testmap:testmap/>
>
> B  <xsl:output method="text"/>
>
> B  <xsl:variable name="vChars" select=
> B  "'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'"
> B  />
>
> B  <xsl:template match="/">
> B  B  <xsl:variable name="vTestMap" select="document('')/*/testmap:*[1]"/>
>
> B  B  <xsl:variable name="vNumericVal">
> B  B  B  B  B  B  B  B  B <xsl:call-template name="str-map">
> B  B  B  B  B  B  B  B  B  B <xsl:with-param name="pFun"
select="$vTestMap"/>
> B  B  B  B  B  B  B  B  B  B <xsl:with-param name="pStr"
select="'IDACQ0LB'"/>
> B  B  B  B  B  B  B  B  B </xsl:call-template>
> B  B  </xsl:variable>
>
> B  B  <xsl:value-of select="$vNumericVal mod 65536"/>
> B  </xsl:template>
>
> B  B <xsl:template name="double" match="testmap:*">
> B  B  B <xsl:param name="arg1"/>
>
> B  B  B <xsl:value-of select="string-length(substring-before
> ($vChars,$arg1))"/>
> B  B </xsl:template>
>
> </xsl:stylesheet>
>
>
>
> --
> Cheers,
> Dimitre Novatchev
> ---------------------------------------
> Truly great madness cannot be achieved without significant intelligence.
> ---------------------------------------
> To invent, you need a good imagination and a pile of junk
> -------------------------------------
> Never fight an inanimate object
> -------------------------------------
> You've achieved success in your field when you don't know whether what
> you're doing is work or play
>
>
>
> On Fri, Jul 24, 2009 at 4:06 PM, Dimitre Novatchev<dnovatchev@xxxxxxxxx>
> wrote:
>> Hermann,
>>
>>> Now these values look different for different browsers, and need to
>>> "somehow"
>>> be converted to a seed value for FXSLs random generator.
>>>
>>> Ideas?
>>
>>
>> You could try something simple as the following:
>>
>> B  sum(string-to-codepoints($pId)) B  mod B  65536
>>
>>
>> and see that the results' variety is satisfactory.
>>
>> --
>> Cheers,
>> Dimitre Novatchev
>> ---------------------------------------
>> Truly great madness cannot be achieved without significant intelligence.
>> ---------------------------------------
>> To invent, you need a good imagination and a pile of junk
>> -------------------------------------
>> Never fight an inanimate object
>> -------------------------------------
>> You've achieved success in your field when you don't know whether what
>> you're doing is work or play
>>
>>
>>
>>
>> On Fri, Jul 24, 2009 at 3:28 PM, Hermann
>> Stamm-Wilbrandt<STAMMW@xxxxxxxxxx> wrote:
>>> Dimitre,
>>>
>>>> > If you have decided to go with a service providing random numbers
> then
>>>> > xslt-ish way (set based) to do it would be a service receiving a
> number
>>> and
>>>> > returning an xml with a specified number of random numbers.
>>>> >
>>>>
>>>> Using a service to provide a random sequence is much more unreliable
>>>> and inefficient than just doing this in pure XSLT, as this has been
>>>> done by FXSL for many years:
>>>>
>>>>
>>>
>
http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXS
L-htm.htm
>
>>>
>>> first of all, FXSL is a cool library and the documentation at the link
> is
>>> informative.
>>>
>>> I tried fxsl-1.2 and installed these necessary files on my webserver:
>>> curry.xsl B iter.xsl B map.xsl B random.xsl B test-random.xsl
>>>
>>> First I realized that it did work on FF3 and not on FF2 (because of the
>>> missing
>>> support of exslt:node-set there). Then I tried it on IE6 and it did not
>>> work first.
>>> After applying below patch it worked under IE6, too.
>>> You may try it out here:
>>>
> http://www.stamm-wilbrandt.de/en/xsl-list/random/fxsl-1.2/test-random.xml
>>>
>>> The output is the same as generated by eg. "xsltproc test-random.xsl
>>> some.xml", but
>>> it is ALWAYS THE SAME output (try it repeatedly).
>>>
>>> I knew of the different techniques in generating pseudo random numbers
> but
>>> what
>>> is really needed is to be able to provide a changing seed (eg.
> initialize
>>> with
>>> the number of seconds since 1/1/1970, time(NULL) in C).
>>>
>>> Then I remembered the generate-id use of Scott, and after reading
> Michaels
>>> last
>>> post the following fragment seems to be an always changing value:
>>> http://www.stamm-wilbrandt.de/en/xsl-list/random/scott.xml
>>>
>>> B  B  B  B <xsl:variable name="seed"><a/></xsl:variable>
>>> B  B  B  B <xsl:value-of select="generate-id(exsl:node-set($seed))" />
>>>
>>> Now these values look different for different browsers, and need to
>>> "somehow"
>>> be converted to a seed value for FXSLs random generator.
>>>
>>> Ideas?
>>>
>>>
>>>
>
=============================================================================
>
>>> from "
> http://dpcarlisle.blogspot.com/2007/05/exslt-node-set-function.html"
>>> $ diff random.xsl.orig random.xsl
>>> 20c20,21
>>> < B exclude-result-prefixes="xsl ext randScale myRandNext
>>> mySingleRandDistFun x"
>>> ---
>>>> B xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>>>> B exclude-result-prefixes="xsl ext msxsl randScale myRandNext
>>> mySingleRandDistFun x".
>>> 30a32,36
>>>> B  <msxsl:script language="JScript" implements-prefix="ext">
>>>> B  B  this['node-set'] = B function (x) {
>>>> B  B  B  return x;
>>>> B  B  }
>>>> B  </msxsl:script>
>>> $
>>>
>>>
>>>
>>> Mit besten GrC<Cen / Best wishes,
>>>
>>> Hermann Stamm-Wilbrandt
>>> Developer, XML Compiler
>>> WebSphere DataPower SOA Appliances
>>> ----------------------------------------------------------------------
>>> IBM Deutschland Research & Development GmbH
>>> Vorsitzender des Aufsichtsrats: Martin Jetter
>>> GeschC$ftsfC<hrung: Erich Baier
>>> Sitz der Gesellschaft: BC6blingen
>>> Registergericht: Amtsgericht Stuttgart, HRB 243294
>>>
>>>
>>>
>>> B  B  B  B  B  B  Dimitre Novatchev
>>> B  B  B  B  B  B  <dnovatchev@gmail
>>> B  B  B  B  B  B  .com>
> To
>>> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>>> B  B  B  B  B  B  07/24/2009 11:00
> cc
>>> B  B  B  B  B  B  PM
>>>
> Subject
>>> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  Re:  Re:
question on random
>>> B  B  B  B  B  B  Please respond to B  B  B  B  numbers for browser XSLT
>>> B  B  B  B  B  B  xsl-list@xxxxxxxx
>>> B  B  B  B  B  B  B lberrytech.com
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> If you have decided to go with a service providing random numbers then
>>>> xslt-ish way (set based) to do it would be a service receiving a number
>>> and
>>>> returning an xml with a specified number of random numbers.
>>>>
>>>
>>> Using a service to provide a random sequence is much more unreliable
>>> and inefficient than just doing this in pure XSLT, as this has been
>>> done by FXSL for many years:
>>>
>>>
>>>
>
http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXS
L-htm.htm
>
>>>
>>>
>>>
>>> --
>>> Cheers,
>>> Dimitre Novatchev
>>> ---------------------------------------
>>> Truly great madness cannot be achieved without significant intelligence.
>>> ---------------------------------------
>>> To invent, you need a good imagination and a pile of junk
>>> -------------------------------------
>>> Never fight an inanimate object
>>> -------------------------------------
>>> You've achieved success in your field when you don't know whether what
>>> you're doing is work or play
>>>
>>>
>>>
>>> On Fri, Jul 24, 2009 at 1:48 PM, Vladimir
>>> Nesterovsky<vladimir@xxxxxxxxxxxxxxxxxxxx> wrote:
>>>> If you have decided to go with a service providing random numbers then
>>>> xslt-ish way (set based) to do it would be a service receiving a number
>>> and
>>>> returning an xml with a specified number of random numbers.
>>>> --
>>>> Vladimir Nesterovsky
>>>> http://www.nesterovsky-bros.com/
>>>>
>>>>
>>>>> To Ben:
>>>>> 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:
>>>>> ...
>>>>> ...
>>>>> B  B <xsl:choose>
>>>>> B  B  B <xsl:when test="function-available('exsl:node-set')">
>>>>> B  B  B  B <xsl:value-of select="document(concat('/cgi-bin/rand.pl?',
>>>>
>>>> $scale,
>>>>>
>>>>> '&amp;x=', generate-id(exsl:node-set($seed))))" />
>>>>> B  B  B </xsl:when>
>>>>> B  B  B <xsl:when test="function-available('msxsl:node-set')">
>>>>> B  B  B  B <xsl:value-of select="document(concat('/cgi-bin/rand.pl?',
>>>>
>>>> $scale,
>>>>>
>>>>> '&amp;x=', generate-id(msxsl:node-set($seed))))" />
>>>>> B  B  B </xsl:when>
>>>>> ...
>>>>
>>>> I tried your solution and after replacing '&amp;x=' with '+' it
> directly
>>>> worked on my local web server!
>>>> (I did not know that generate-id works in a browser)
>>>>
>>>> But as already posted it did not work after installed on my real
>>> webserver
>>>> because that does not have enough power to handle the six document
> opens.
>>>>
>>>> Btw, I really like the solution of David Carlisle to provide
>>> exslt:node-set
>>>> for IE browsers (and not having to deal with exslt/msxml):
>>>> http://dpcarlisle.blogspot.com/2007/05/exslt-node-set-function.html
>>>
>>>
>>
>>
>>
>> --
>> Cheers,
>> Dimitre Novatchev
>> ---------------------------------------
>> Truly great madness cannot be achieved without significant intelligence.
>> ---------------------------------------
>> To invent, you need a good imagination and a pile of junk
>> -------------------------------------
>> Never fight an inanimate object
>> -------------------------------------
>> You've achieved success in your field when you don't know whether what
>> you're doing is work or play

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-2013 All Rights Reserved.