A little Divinitation with generate-id()?

Subject: A little Divinitation with generate-id()?
From: John Robert Gardner <jrgardn@xxxxxxxxx>
Date: Thu, 11 May 2000 22:58:28 -0400 (EDT)
Assuming I have 8 possible outcomes, I would want to randomly call one of
them (a sort of binary with 000, 001, 010, 011, 100, 101, 110, and 111
could work also, thereby requiring that I only need to call two random odd
or even integers, iterate it as need be in triads, to get my 0-7
range), I could do this with an <xsl:if test="false()">, for whether it
was 1 or 0, odd or even, whichever . . . the trick is getting something
_external_ to the stylesheet, somewhat randomly generated, into it to test
for odd/even, 1 or 0.  

Of course, I suppose, generate-id()is the ideal way to go, but how would I
construct my stylesheet so that I could be absolutely certain the id was
random and not dependent upon the input?  I would wish to somehow control
the range of possible id's. 

What I'm working with is this xml:

<a>1</a>
<b>0</b>
<a>1</a>
<a>1</a>
<b>0</b>
<a>1</a>
<b>0</b>
<b>0</b>
<a>1</a>
<b>0</b>

And this xsl (which isn't working)

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl='http://www.w3.org/XSL/Transform/1.0'> 

<xsl:output method="text" />
<xsl:template match="/" >
<xsl:variable name="throw" select="generate-id()" />
<xsl:when test="$throw position() = last[not(number(1, 3, 5, 7, 9))]">
	<xsl:value-of select="*[position(., $throw)=1]" />
</xsl:when>
<xsl:otherwise>
	<xsl:value-of select="../following::sibling" />
	<xsl:value-of select="../*" />
</xsl:otherwise>
<xsl:variable name="toss" select="generate-id()" />
<xsl:value-of select="$toss position() = last" />
</xsl:template>

</xsl:stylesheet>

I wrote this assuming that "generate-id()" could randomize in and of
itself, so I wouldn't need to call outside (following Kay, p. 463, "The
only guarantee about the result is that it is different for every node").

So I'm trying to check the odd or even value of the last position in the
id generated, and it it's even (not 13579), select what's at that spot in
the sequence of nodes.  Otherwise, if odd, take it's following sibling.
Then do the following sibling thereof, and then grab a third random number
from generate id, and select it as my third node of output.

I'm seeking a random output, differing for any given calling of the sheet,
that contains one triad of 1's and/or 0's per above.  So I'm only looking,
at any given time, to select 3 nodes in the output.  Accordingly, it seems
I need only "hop into" my source at some random point (position()=1, 2, 3,
4, or 5), and then jump to a following sibling based on whether it's odd
or even, and from there grab one additional random spot.



=-=-=-=-=-=-=-=-=-==-=-=-=
John Robert Gardner, Ph.D.
XML Engineer
Emory University
------------------------------------------------------------
http://vedavid.org/diss/
"If there is something you're thinking of doing, or wish you could do,
begin it.  In boldness there is mystery and power . . . . "  -Goethe


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread