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:
http://stamm-wilbrandt.de/en/xsl-list/random/rand6.xml
$ cat rand6.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="rand6.xsl"?>
<tag/>
$ cat rand6.xsl
<xsl:stylesheet
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"
select="document('/cgi-bin/rand.pl?6')"/>
<html><body>rand(6): <xsl:value-of select="$rand"/></body></html>:
</xsl:template>
</xsl:stylesheet>
$
$ 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
Geschäftsführung: Erich Baier
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--