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

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

问题描述

我正在自定义Google Search Appliance,该设备使用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天全站免登陆