[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Randomly displaying articles from RSS feed


Subject: Re: [xsl] Randomly displaying articles from RSS feed
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 11 Jan 2008 12:29:08 -0500

At 07:29 PM 1/10/2008, Abel wrote:
A quite processor-neutral approach is to use a URL that creates your random number on each request (for multiple requests, make sure the url is unique by using the query part of it, otherwise the processor will not do a second request to the same url as the specs require to requests to the same url to be stable).

Another approach with XSLT 2.0 is to use a newly create node (a function can create a node each time again) and use the generate-id of it. This will not provide randomness, but does provide uniqueness within one process.

Cool. I don't think the newly created node ID will work for the use case, but the external URL call is excellent (and part of a trend, ain't it). Of course, the URL will have to return a number random across calls, not just the same "random" number each time. :-)


In my earlier reply to Brent's post, I also said that if one had a random number, the weighting part of the problem would be relatively easy. I've since been thinking about that, and now I'm not so sure. I have a solution to it, but it's not an especially easy one, at least for a beginner (although I think it is creative :-). But I wonder if an easier one is out there.

So, let's say we have

<feeds>
  <feed weight="15">Reference A</feed>
  <feed weight="50">Reference B</feed>
  <feed weight="20">Reference C</feed>
  <feed weight="15">Reference D</feed>
</feeds>

... and we can presume a parameter $R giving us a random-for-our-purposes value between 0 and 1.

How do we best filter this list into a single 'feed', getting Reference B half the time, C 20% of the time, and A and D each 15% of the time?

Do not assume that the weights will always add to 100.

As I said, I have a solution in mind, but I trust the list to come up with a better one.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
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
======================================================================


Current Thread
Keywords