How can get RANDOM record from XML file?

D

Diodak

****************************************
How can get RANDOM record from XML file?
****************************************
for e.g. in xml files i have aprox.200 records.
how get random position and display that in html.
My Xml (and english) i'ts very poor.
Help..... maybe some solution or example.
Thanks !
****************************************
 
M

Martin Honnen

Diodak said:
****************************************
How can get RANDOM record from XML file?
****************************************
for e.g. in xml files i have aprox.200 records.
how get random position and display that in html.
My Xml (and english) i'ts very poor.
Help..... maybe some solution or example.

If you are using XSLT you could use the random extension from
http://www.exslt.org/random/functions/random-sequence/index.html to
generate a random number and then index some elements as needed.
 
D

Diodak

Thank's but this solution not exacly what i want.
I want display only one from recordcount and that one mast be
integer and random. Maybe my english is to poor to explain that.
//part of xml file
<galeria>
<foto>
<min>1m.jpg</min>
<max>1.jpg</max>
<data>2004.04.04</data>
<autor>Marcin</autor>
<kat>Przyroda</kat>
</foto>
<foto>
<min>2m.jpg</min>
<max>2.jpg</max>
<data>2004.03.08</data>
<autor>Anna</autor>
<kat>Krajobraz</kat>
</foto>
.............
</galeria>
I want display random node 'foto'

How i can do that?
Please give me hint or part of source xsl file

Best Regards!

__________________________________________________
U¿ytkownik "Dimitre Novatchev said:
See:
"Casting the Dice with FXSL: Random Number Generation Functions in XSLT"
at:

http://fxsl.sourceforge.net/articles/Random/Casting the Dice with FX
SL-htm.htm

This is pure XSLT 1.0 (and also 2.0) code.


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


Martin Honnen said:
If you are using XSLT you could use the random extension from
http://www.exslt.org/random/functions/random-sequence/index.html to
generate a random number and then index some elements as needed.
 
D

Dimitre Novatchev [MVP XML]

Diodak said:
Thank's but this solution not exacly what i want.
I want display only one from recordcount and that one mast be
integer and random. Maybe my english is to poor to explain that.
//part of xml file
<galeria>
<foto>
<min>1m.jpg</min>
<max>1.jpg</max>
<data>2004.04.04</data>
<autor>Marcin</autor>
<kat>Przyroda</kat>
</foto>
<foto>
<min>2m.jpg</min>
<max>2.jpg</max>
<data>2004.03.08</data>
<autor>Anna</autor>
<kat>Krajobraz</kat>
</foto>
............
</galeria>
I want display random node 'foto'

How i can do that?
Please give me hint or part of source xsl file

In the quoted article there is an example with source code
(test1-random.xsl) of generating 100 randoms in the range [1, 10].

Use the same code to generate one (or whatever number of randoms you need)
random in the range [1, count(/galeria/foto)]. Let's have this random in a
xsl:variable named $theRand.

Then your random node is:

/galeria/foto[$theRand]


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 
D

Diodak

Thank's again!
MSIE5 don't support: count(/galeria/foto) and if i use Variable same too :(
 
D

Dimitre Novatchev [MVP XML]

Diodak said:
Thank's again!
MSIE5 don't support: count(/galeria/foto) and if i use Variable same too
:(

You were asking an *XSLT* question -- this has little to do with IE5 (a
browser).

IE5 can "support" true XSLT if MSXML3 isinstalled in "replace mode" -- just
search for:
msxml3 replace mode


Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top