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

question on random numbers for browser XSLT

Subject: question on random numbers for browser XSLT
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Wed, 22 Jul 2009 14:43:03 +0200
 question on random numbers for browser XSLT
I want random numbers in a stylesheet but I am bound to XSLT 1.0 and
not able to make use of "http://exslt.org/random" extensions because
the stylesheet should be accessed by <?xml-stylesheet ...?> in a
browser XML document.

Is there a pure XSLT solution?
(the quality of the generated random numbers is not that important)

After some playing around I found below (not pure XSLT) solution.
Important is that the PERL script lives in the same domain as the
stylesheet. You may try it out (random number "0-5") by clicking here:

$ cat rand6.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="rand6.xsl"?>

$ cat rand6.xsl
  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="UTF-8"/>

  <xsl:template match="/">
    <xsl:variable name="rand"
    <html><body>rand(6): <xsl:value-of select="$rand"/></body></html>:


$ cat cgi-bin/rand.pl
#!/usr/bin/perl -w.

print "Content-type: text/xml\n\n";

printf("<?xml version=\"1.0\"?>\n");
printf("<rand>%d</rand>\n", rand($ARGV[0]));
printf("<!-- PERL rand(%d) -->\n",$ARGV[0]);

Mit besten Gr|_en / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschdftsf|hrung: Erich Baier
Sitz der Gesellschaft: Bvblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

Current Thread


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.
First Name
Last Name
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.