Home > Article > Backend Development > Implementing random ordering in XSL/XSLT
Like database sorting, XSL/XSLT can also implement random sorting. The principle is also very simple. The following is the code.
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:eMeng="http://dotnet.aspx.cc/" version="1.0"> <msxsl:script language="javaScript" implements-PRefix="eMeng"> function Random() { return Math.random(); } </msxsl:script> <xsl:template match="/"> <xsl:for-each select="/*/node()"> <xsl:sort select="eMeng:Random()"/> <xsl:value-of select="."/> <br/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
The above is the content of implementing random sorting in XSL/XSLT. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!