和數(shù)據(jù)庫(kù)排序一樣,XSL/XSLT也可以實(shí)現(xiàn)隨機(jī)排序,原理也很簡(jiǎn)單,下面就是代碼。 <?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>
|
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!