在 xslt 1.0 中随机排序? [英] Randomize sorting in xslt 1.0?

查看:24
本文介绍了在 xslt 1.0 中随机排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,在 XSLT 1.0 中是否有任何方法可以进行随机排序?

I would like to know, is there is any way to do random sorting in XSLT 1.0?

这是我的 XML

<root><DO status="a">text comes here</DO><DO status="b">text comes here</DO><DO status="c">text comes here</DO><DO status="d">text comes here</DO><DO status="e">text comes here</DO></root>

期望的输出:

<root><DO status="c">text</DO><DO status="a">text comes here</DO><DO status="b">text comes here</DO><DO status="e">text comes here</DO><DO status="d">text comes here</DO></root>

希望我的问题很清楚?

提前致谢

推荐答案

我想知道,在 XSLT 1.0 中是否有任何方法可以进行随机排序?

I would like to know, is there is any way to do random sorting in XSLT 1.0?

使用 vanilla XSLT 1.0 - 否.

With vanilla XSLT 1.0 - No.

您可以使用扩展来访问外部语言的随机器并将该函数放入xsl:sort.例如,使用 msxsl 扩展访问 Windows 脚本语言:

You could use an extension to access the randomizer of an external language and put that function into xsl:sort. For example, using the msxsl extension to access Windows Scripting languages:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:my="http://tempuri.org/myscripts" 
  exclude-result-prefixes="msxsl my"
>

  <msxsl:script language="JScript" implements-prefix="my">
    function random() {
      return Math.random();
    }
  </msxsl:script>

  <xsl:template match="root">
    <xsl:for-each select="DO">
      <xsl:sort select="my:random()" data-type="number" />
      <xsl:copy-of select="." />
    </xsl:for-each>
  </xsl:template> 

</xsl:stylesheet>

这篇关于在 xslt 1.0 中随机排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆