Home >Backend Development >XML/RSS Tutorial >Implementing random ordering in XSL/XSLT

Implementing random ordering in XSL/XSLT

黄舟
黄舟Original
2017-03-02 17:20:131427browse

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)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn