Search

And here are my results:

designermonkey:xslt designermonkey$ xsltproc transform.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
designermonkey:xslt designermonkey$ xsltproc transform.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
designermonkey:xslt designermonkey$ xsltproc transform.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
designermonkey:xslt designermonkey$ xsltproc transform.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
designermonkey:xslt designermonkey$ xsltproc transform.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
designermonkey:xslt designermonkey$ 

The number is the same every time... Weird.

Funny, it's the same number in my Terminal:

imacoda:Desktop me$ xsltproc style.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
imacoda:Desktop me$ xsltproc style.xsl data.xml
<?xml version="1.0"?>
0.394613364429499
imacoda:Desktop me$ xsltproc style.xsl data.xml
<?xml version="1.0"?>
0.394613364429499

In my (Mac) terminal math:random always outputs the same number. But this number depends on where the function is called. If I try this:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    xmlns:math="http://exslt.org/math"
    extension-element-prefixes="exsl math">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/">
    <xsl:value-of select="math:random()"/>
    <xsl:text>
</xsl:text>
    <xsl:call-template name="testme"/>
</xsl:template>

<xsl:template name="testme">
    <xsl:value-of select="math:random()"/>
</xsl:template>

</xsl:stylesheet>

the output is:

imacoda:Desktop me$ xsltproc style.xsl data.xml
<?xml version="1.0"?>
 7.82636925942561e-06
0.131537788143166
imacoda:Desktop me$ xsltproc style.xsl data.xml
<?xml version="1.0"?>
 7.82636925942561e-06
0.131537788143166
imacoda:Desktop me$ xsltproc style.xsl data.xml
<?xml version="1.0"?>
 7.82636925942561e-06
0.131537788143166

So I guess that there is indeed a problem in the implementation.

It seems so. If I call the function twice in the same transformation, I get two different numbers. I wonder where I could log this as an issue :S

Interesting. After having had a deeper look at the libxslt code I found out that math:random is missing its seed. Apparently the libxslt mailing list had a discussion about it in 2008 but never pursued or patched it.

I am not really sure why the random numbers on my machine looked random before... simply value-offing math:random always produces the very same number.

Also, it is noteworthy that development on libxslt is not dead yet. I'll try come up with a solution and post a patch to the mailing list; let's see what happens. :-)

Awesome dude.

Alright, I've posted my patch.

And BAM, I have cemented myself in the very heart and soul of the XSLT you all are using! :-D

Nils, you're now open source famous.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details