I have an XML file that contains nodes like this:
<values>
<item>item 1</item>
<item>item 2</item>
<item>item 3</item>
<item>item 4</item>
<item>item 5</item>
</values>
I would like to get the list in a randomize order using xslt:
<values>
<item>item 3</item>
<item>item 5</item>
<item>item 1</item>
<item>item 4</item>
<item>item 2</item>
</values>
I cannot use external resources like "xmlns:java="java.lang.Math" and "xmlns:math="http://exslt.org/math"
because of limitation.
maybe this links might help:
http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXSL-htm.htm
The following stylesheet will write the items to the output tree in random order. The stylesheet expects an external "initial-seed" number to be supplied at runtime as a parameter.
Note: since the items are only re-ordered without processing, it is not necessary to sort them, and the EXSLT node-set() function will not be required here after all.
Applied to your input with the default initial-seed (123), the output is:
When performed with a seed of 1234, the output is: