Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Jesper Tverskov <jesper.tverskov@-----.--->
To: xsl-list@-----.------------.---
Date: 10/4/2009 8:05:00 PM
On Fri, Oct 2, 2009 at 7:11 PM, Dimitre Novatchev <dnovatchev@g...> 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 &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"/>
   </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

--~------------------------------------------------------------------
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@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent