[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Creating an array

Subject: RE: Creating an array
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 27 May 2003 09:27:16 -0400
xsl create array
[Alan Gardner]
> 
> I'm trying to create the ability to select nodes at random 
> (easy enough),
> however I'm getting duplicates. I've tried to create a string 
> (an array if
> you will) of numbers that I generated that I can check each 
> time I loop
> through the nodes, but if it is possible, it's outside of my 
> current xsl
> understanding.
> 
> Is it possible to build a delimited string/array? Or does anyone have
> suggestions on how to eliminate duplicates while generating 
> random numbers
> in the first place?
> 

Well, you cannot build up a global variable (or any variable) as you go
since they cannot be changed after creation.  So you would have to use
some kind of recursion and pass the previously-selected nodes in a
parameter.  At some point you would come up against the limits on
recursion.

Leaving aside recursion limits, for each node you randomly select you
could add the value of its generate-id() to a space-separated list of
previous generate-id() values.  You would use contains() to see if you
had already selected a node.

If you know you will only randomly select a certain maximum number of
nodes, then you could create a list of random numbers in that range
outside of xslt and put them into a lookup element in the stylesheet.  I
used this method once - I had to dither the position of some (x,y)
points that would have been on top of each other otherwise (for an svg
output), but I did not have to bother about duplicates.

If you go beyond xslt 1.0, you may be able to build up your list in a
variable and then convert it to a nodeset (I say "may" because whether
it will work depends on the size of the nodeset and the processor - I
have hit strange limits a few times).  This could give you more
flexibility.

I imagine that Mike Kay or Jeni will tell us how xslt2 will make it
easier.

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.