XSLT 中的随机项 [英] Random Items in XSLT

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

问题描述

我正在定制一个 Google Search 设备,它使用 XSLT 向用户显示结果.我们的设计要求在结果页面上随机包含多个图像之一.有没有办法在 XSLT 中使用随机性?(伪随机性对这个应用来说很好.)

I'm customizing a Google Search appliance, which uses XSLT to present results to the user. Our design calls for one of several images to be included randomly on the results page. Is there a way to use randomness in XSLT? (Pseudo-randomness is just fine for this application.)

调用随机模板就可以了,就像能够生成一个随机数和基于它的分支一样.

Calling random templates would be fine, as would just being able to generate a random number and branch based on that.

推荐答案

根据您的平台 XSL 允许注入用户代码,如 C#.我不推荐这个.更好的是,我会让您的 XSL 接受一个参数以及生成 XML 有效负载或 XSLT 的任何内容,并且还可以生成随机数,设置参数.我完全使用这种方法完成了这项工作,只是数据来自 Bing,而不是 G.

Depending on your platform XSL allows inject of user code like C#. I don't recommend this. Better, I would have your XSL accept a parameter and whatever is generating your XML payload or XSLT and can also generate the random number, setting the parameter. I've done this exactly using this approach except the data came from Bing, not G.

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

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