I've got a simple xsl code to display some dynamically xml.
<xsl:template match="/">
<xsl:for-each select="NewDataSet/Vehicle">
<div class="item">
<xsl:value-of select="ManufacturerName" /><br />
<xsl:value-of select="Model" /><br />
<xsl:value-of select="Colour" /><br />
£<xsl:value-of select='format-number(Price, "###,###,##0.")' />
</div>
</xsl:for-each>
</xsl:template>
What I'd like to be able to do is display X number of random distinct node sets instead of all of them. Is this possible using xslt 1.0?
Thanks.
Here is an example that shows how to pick N random nodes out of a given node-set.
You must have a method to generate a random number between 0 and 1 (not including 1) to make this work. In this example, the EXSLT math:random() extension function is used for this purpose. If you are using the MSXML processor, replace this with an extension function as shown here: https://stackoverflow.com/a/6607235/3016153
XML
XSLT 1.0
Result (of an example run)
Note: This method preserves the internal order of the selected items.