Subject: [xsl] Seed problem in FXSL randomizeList From: Jesper Tverskov <jesper@xxxxxxxxxxx> Date: Tue, 6 Oct 2009 11:35:29 +0200 |
I have tested the FXSL randomizeList template for a list of type items/item. For each item I want the positions of the other item elements returned in random order, and I need to make use of the first four items in each random order. The items/item list I have used so far has 140 item elements. I have managed to solve the above using recursion, Saxon and the command line. Processing time is a little less than 10s. The first seed is made like this xs:integer(format-time(current-time(), '[s][f]')). For the next seed I add 11, etc. It is a mystery to me, that if I increase the values of "11" to just "12" the transformation seems to go looping. Millions of lines are generated and I have to stop the process. (I have tested this strange behavior many times). Also the random order of the positions returned, are not that random. The first third of my lists start with the same position number, the next third of the list adds just one to this number, and the last third of the list adds two. The rest of the positions look ok, at least I have not yet recognized a pattern. _Here is my question_. Is there anything I can do to get "random" lists returned, that are more "random" for the first position? And how can I change the XSLT stylesheet so it will also work for lists of items of at least a couple of thousands without the need for experimenting to find a number to add to the first seed that will not break the transformation? <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://fxsl.sf.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="f xs"> <xsl:import href="../../../../XSLT/fxsl-xslt2/fxsl-xslt2/f/randomList.xsl"/> <!-- Can be applied on any source xml document (ignored) --> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="/"> <items> <xsl:call-template name="item"/> </items> </xsl:template> <xsl:template name="item"> <xsl:param name="pSeed" as="xs:integer" select="xs:integer(format-time(current-time(), '[s][f]'))"/> <xsl:param name="num" select="1" as="xs:integer"/> <item> <name> <xsl:value-of select="/items/item[$num]/name"/> </name> <xsl:variable name="x"> <xsl:call-template name="randomizeList"> <xsl:with-param name="pList" select="(1 to count(/items/item))[. != $num]"/> <xsl:with-param name="pSeed" select="$pSeed" as="xs:integer"/> </xsl:call-template> </xsl:variable> <positions> <xsl:sequence select="$x/el[position() < 5]"/> </positions> </item> <xsl:if test="$num < count(/items/item)"> <xsl:call-template name="item"> <xsl:with-param name="pSeed" select="$pSeed + 11" as="xs:integer"/> <xsl:with-param name="num" select="$num + 1" as="xs:integer"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> Cheers, Jesper http://www.xmlplease.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] SGML Inclusions and infin, Don Smith | Thread | Re: [xsl] Seed problem in FXSL rand, Dimitre Novatchev |
RE: [xsl] Fwd: Is this a Saxon Bug , Michael Kay | Date | [xsl] Moving Specific content/eleme, Ramkumar |
Month |