By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

How can get RANDOM record from XML file?

P: n/a
****************************************
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 !
****************************************
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a


Diodak wrote:
****************************************
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/function...nce/index.html to
generate a random number and then index some elements as needed.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
See:
"Casting the Dice with FXSL: Random Number Generation Functions in XSLT"
at:

http://fxsl.sourceforge.net/articles...20FXSL-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" <ma*******@yahoo.de> wrote in message
news:40******@olaf.komtel.net...


Diodak wrote:
****************************************
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/function...nce/index.html to
generate a random number and then index some elements as needed.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

P: n/a
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 [MVP XML]" <dn********@yahoo.com> napisał w
wiadomo¶ci news:c5************@ID-152440.news.uni-berlin.de...
See:
"Casting the Dice with FXSL: Random Number Generation Functions in XSLT"
at:

http://fxsl.sourceforge.net/articles...ce%20with%20FX
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" <ma*******@yahoo.de> wrote in message
news:40******@olaf.komtel.net...


Diodak wrote:
****************************************
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/function...nce/index.html to
generate a random number and then index some elements as needed.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Jul 20 '05 #4

P: n/a

"Diodak" <di*****@poczta.onet.pl> wrote in message
news:c5**********@news.onet.pl...
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
Jul 20 '05 #5

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


Jul 20 '05 #6

P: n/a

"Diodak" <di*****@poczta.onet.pl> wrote in message
news:c5**********@news.onet.pl...
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
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.