Re: [xsl] Randomly displaying articles from RSS feed

Subject: Re: [xsl] Randomly displaying articles from RSS feed
From: Alice Wei <ajwei@xxxxxxxxxxx>
Date: Thu, 10 Jan 2008 15:06:21 -0500

The only hard part of what you're describing is the "randomly" part.
XSLT by itself provides no random or pseudo-random number generation.
I am not exactly sure if you really meant displaying these articles randomly if you want articles appearing more often than the rest.

You can get around this, or through it, by:

* calling out to your environment, e.g. with an extension function,
to get a random number

If you want to, say generate something like have certain articles print out more often than the others, for the function part, you can use

<xsl:function name="functx:dateTime" as="xs:dateTime"
             xmlns:functx=""; >
  <xsl:param name="hour" as="xs:anyAtomicType"/>
 <xsl:param name="minute" as="xs:anyAtomicType"/>
 <xsl:param name="second" as="xs:anyAtomicType"/>

 <xsl:sequence select="


to get what you might want to do. This preserves the minute, second and hour that you could customize into your <xsl:if> statements. You can actually then control the variables and have those that are certain numbers to do certain things.

* passing in a random or virtually-random number as a parameter, and
using that
* using FXSL, which provides support for generating pseudo-random
numbers (this requires
  invoking FXSL libraries)
* other possibilities I may be neglecting

Which of these is best will depend on externals, such as which
processor you're using, whether an extension function or (say) FXSL
is more feasible for you, and so forth.

Lick that problem and the rest is straightforward, as XSLT can handle
the weighting part of it (providing, of course, the weights are
available as source data).

For FXSL on this, see


At 02:34 PM 1/10/2008, you wrote:

I have an RSS feed that I use to display articles on
my website.  I would like to randomly display one
article at a time, but I want to be able to
artificially weight the articles so that article 1
comes up %50 of the time, article 2 comes up 25% of
the time, etc.

Is this something that XSL is capable of doing?

Please and thank you.

Brent Wilcox

Never miss a thing.  Make Yahoo your home page.

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

Alice Wei MIS 2008 School of Library and Information Science Indiana University Bloomington ajwei@xxxxxxxxxxx

Current Thread