BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


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


Uncategorized
Sorting the results and use the Axis
TreeMaker
XMLEditor - WebClipping
WDDX Parser
Templx: x++ IDE Released!
XppEngCOM: COM implementation of x++ interpreter
Backup Outlook mail as XML
Grouping and Summing the values in XML
WDDX Parser (updated bug)
DIME Parser and Generator (C#)
Flash menu using XML
Virtual Directory Utilities for IIS(C#)
ComSerialization
Re: Max() function
Stop Tailoring, Create Generic!!!
Introduction to WAP Push
Add xml binding to select list
Ontology Web Language
Wrapping multiple elements in a parent element
Anet XML Search Engine


 
 

<< System.XMLWCF, WS, SOAP >>


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

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 :  

<< System.XMLWCF, WS, SOAP >>





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

 
 

    Email TopXML