BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


XSLT
XPath Analyzer
Finding the Maximum Date
World Cup 2002 fever hits XSLT!!
Using XSLT for DHTML Menus
RSS / RDF Newsfeed Reader
Hierarchical menu from Database + XSL to Html
XSLT syntax hightlighter
XSLT Stylesheet for listing namespaces used in a document
Rotate an SVG shape over it's center
Looping through each letter of the alphabet
An XSL Calculator using the FXSL Functional Programming Library
A Calendar, using the XSelerator's datetime library
Match a phrase to the closest sorted list value with 1 XPath Expression
SVG toolbar
Sort an XML document
Transposing rows into columns using XML/XSLT
XSLT ISAPI Filter for IIS
Browser-Based XML Editor
XSLT function for standardizing address values
Passing Values to XSL (non- addParameter)


 
 

<< XQuery.NET and XML >>


By Dimitre Novatchev
First Posted 05/04/2002
Times viewed 236

Randomization of node-sets or node-lists


break, and I'd also like to be able to present a node-set in a new random order on each call. If either of these effects can be done directly with xsltproc, I'll be one happy camper. -- Gary Lawrence Murphy" I am pleased to present a complete solution for the problem of producing and processing randomized node-sets or node-lists (random indices). This is a XSLT 1.0 solution and can be used immediately. The code bellow is a complete, new module of FXSL, named randomList.xsl. It should be put in the same folder, where all other FXSL files reside. It imports and uses random.xsl. The main functions/templates are: 1. randomizeList -- given a node-set and an optional seed produces a new node-set, having nodes with the same values as the given node-set, but ordered randomly. 2. randomMap -- given a function f, a node-set and an optional seed, it produces a mapping of the given function f over the nodes of the node-set, which is applied in a random order, based on the given seed. It is efficient, because no intermediate randomized list is produced. 3. randListIndex -- given a node-set and an optional seed produces a random index (a random permutation of the numbers from 1 to count($node-set). This index can then be used e.g. in a xsl:for-each loop to index randomly the elements of any node-set with the same number of nodes. The basic idea standing behind a list randomisation is to follow the algorithm of producing a permutation of N elements -- that is to produce one random number out of N in the first stage, then to produce one random number out of the remaining N-1, etc... Actually, a random sequence of N random numbers is produced, and its elements are then individually scaled, so that its k-th element is in the interval [1, N-k+1] In the code section bellow is the complete FXSL module. To test it, we apply the following test transformation (at the end of the XSLT code section to the xml code bellow. And the result of the transformation is also there (because I cannot have any markup text in the "Description section"???). Do enjoy! Cheers, Dimitre Novatchev.

Summary I am pleased to present a complete solution for the problem of producing and processing randomized node-sets or node-lists (random indices). This is a XSLT 1.0 solution and can be used immediately.

From http://sources.redhat.com/ml/xsl-list/2002-04/msg01225.html: "The two transforms I would like to implement seem easy and commonplace, but are proving elusive: I would like to render a node-set into rows of columns without resorting to disable-output-escaping to insert the modulo-column
Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< XQuery.NET and XML >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML