Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

xslt - generate random number in RSS viewer webpart

I am using RSS viewer webpart with the following references:

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:rssaggwrt="http://schemas.microsoft.com/WebParts/v3/rssagg/runtime"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:rssFeed="urn:schemas-microsoft-com:sharepoint:RSSAggregatorWebPart"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"      xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rss1="http://purl.org/rss/1.0/" xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:atom2="http://purl.org/atom/ns#"

Could anyone please suggest me how to generate random number in xsl ?

I tried the following code :

xsl:value-of select="(floor(math:random()*10) mod 10) + 1"

with the following references:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math"

The above references are throwing error. Please help for the same.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your processor does not support the EXSLT math:random() function, then you can:

  1. check the documentation to see if the processor provides extension functions under a different namespace;
  2. write your own extension function using the extension mechanism provided by your processor;
  3. supply a random number to the stylesheet as a parameter at runtime;
  4. derive a random number from the current date/time (if your processor can generate those, or if you can pass them to the stylesheet at runtime) or from some other non-constant data, for example the length of the processed document (knowing the purpose would be helpful here);
  5. get a random number from a web service.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...