Re: [xsl] RandomList.xsl from FXSL-xslt2

Subject: Re: [xsl] RandomList.xsl from FXSL-xslt2
From: Jesper Tverskov <jesper.tverskov@xxxxxxxxx>
Date: Sun, 4 Oct 2009 22:04:48 +0200
On Fri, Oct 2, 2009 at 7:11 PM, Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:

> It is not necessary at all to "make 300 transformations". Just get a
> random sequence in which every of the 300 items is reperesented
> exactly once (if I remember well, you'll need the "random-index"
> template for this). Then for every item in the sequence get it
> together with the four that are its neighbors (for example the item
> plus the two preceding and the two following -- with minor exceptions
> for items that are at the ends of the sequence).

Sounds like an interesting approach, but for the time being I'm using
an XSLT 2.0 solution of one transformation using recursion (turned out
to be not that difficult after all):

<xsl:stylesheet version="2.0" xmlns:xsl="";
 xmlns:f=""; xmlns:xs="";
 <xsl:import href="../f/randomList.xsl"/>

 <!-- Can be applied on any source xml document (ignored) -->
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
   <xsl:call-template name="item"/>

 <xsl:template name="item">
  <xsl:param name="pSeed" as="xs:integer"
select="xs:integer(format-time(current-time(), '[f][s]'))"/>
  <xsl:param name="num" select="1"/>
    <xsl:value-of select="/items/item[$num]/name"/>
   <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:if test="$num &lt; count(/items/item)">
   <xsl:call-template name="item">
    <xsl:with-param name="pSeed" select="$pSeed +  $pSeed" as="xs:integer"/>
    <xsl:with-param name="num" select="1 + $num"/>

Is the proposed method of Dimitre Novatchev better than using
recursion? Can my recursion solution be improved?


Current Thread