How can get RANDOM record from XML file?

Discussion in 'XML' started by Diodak, Apr 16, 2004.

  1. Diodak

    Diodak Guest

    ****************************************
    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 !
    ****************************************
    Diodak, Apr 16, 2004
    #1
    1. Advertising

  2. 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/functions/random-sequence/index.html to
    generate a random number and then index some elements as needed.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 16, 2004
    #2
    1. Advertising

  3. See:
    "Casting the Dice with FXSL: Random Number Generation Functions in XSLT"
    at:

    http://fxsl.sourceforge.net/articles/Random/Casting the Dice with FXSL-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" <> wrote in message
    news:...
    >
    >
    > 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/functions/random-sequence/index.html to
    > generate a random number and then index some elements as needed.
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    >
    Dimitre Novatchev [MVP XML], Apr 16, 2004
    #3
  4. Diodak

    Diodak Guest

    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]" <> napisa³ w
    wiadomo¶ci news:c5oug2$4b24f$-berlin.de...
    > 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" <> wrote in message
    > news:...
    > >
    > >
    > > 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/functions/random-sequence/index.html to
    > > generate a random number and then index some elements as needed.
    > > --
    > >
    > > Martin Honnen
    > > http://JavaScript.FAQTs.com/
    > >

    >
    >
    Diodak, Apr 18, 2004
    #4
  5. "Diodak" <> wrote in message
    news:c5tekc$mft$...
    > 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
    Dimitre Novatchev [MVP XML], Apr 18, 2004
    #5
  6. Diodak

    Diodak Guest

    Thank's again!
    MSIE5 don't support: count(/galeria/foto) and if i use Variable same too :(
    Diodak, Apr 18, 2004
    #6
  7. "Diodak" <> wrote in message
    news:c5tp6f$19a$...
    > 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
    Dimitre Novatchev [MVP XML], Apr 18, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SnVzdGlu?=

    Retrieving Record Key while creating the record.

    =?Utf-8?B?SnVzdGlu?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    629
    =?Utf-8?B?SnVzdGlu?=
    Oct 5, 2004
  2. Kevin
    Replies:
    19
    Views:
    1,128
    Tris Orendorff
    Feb 13, 2006
  3. globalrev
    Replies:
    4
    Views:
    753
    Gabriel Genellina
    Apr 20, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    657
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,153
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page