I want to select 30% of values randomly from a XML.As Here is 10 values so , i have to select 3 values randomly.
i have a xml.
<xml>
<value>A</value>
<value>B</value>
<value>C</value>
<value>D</value>
<value>E</value>
<value>F</value>
<value>G</value>
<value>H</value>
<value>I</value>
<value>J</value>
</xml>
I need this value.
<xml>
<value>E</value>
<value>I</value>
<value>J</value>
</xml>
In a modern XSLT 3 implementation supporting the
random-number-generatorfunction you can use e.g.random-number-generator()?permute(/xml/value)[position() = 1 to 3]:So you need an XSLT 3 processor like Saxon 10 in any edition or Saxon 9 PE or EE or AltovaXML 2017 R3 or later.
In XSLT 1, if you have support for EXSLT's
math:random, you can usehttp://xsltransform.net/93Fbify