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="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"> <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="/"> <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(), '[f][s]'))"/> <xsl:param name="num" select="1"/> <item> <name> <xsl:value-of select="/items/item[$num]/name"/> </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:call-template> </item> <xsl:if test="$num < 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"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> Is the proposed method of Dimitre Novatchev better than using recursion? Can my recursion solution be improved? Cheers, Jesper http://www.xmlplease.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] RandomList.xsl from FXSL-, Dimitre Novatchev | Thread | Re: [xsl] RandomList.xsl from FXSL-, Dimitre Novatchev |
Re: [xsl] Correct way to test for n, Dan Vint | Date | [xsl] temporarily enable a characte, Andy Chambers |
Month |