generate random number in RSS viewer webpart

2019-01-20 17:17发布

问题:

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.

回答1:

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.