Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 17th, 2007, 09:10 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default Select nodes randomly

Hi all

I need help to extract some information from my xml randomly...

I have a structure like this:

<country id="1">
<page id="1">
<banner id="1">
<product id="1">...</product>
<product id="2">...</product>
</banner>
<banner id="2">
<product id="3">...</product>
<product id="2">...</product>
</banner>
</page>
<page>...</page>


What I need to do is, for each page, select only one banner containing only product, randomly...
Is it possible to do with xslt?

Thanks.

Reply With Quote
  #2 (permalink)  
Old October 17th, 2007, 09:18 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

XSLT is as a language is defined so that if you run the stylesheet twice with the same parameters you should get the same output, therefore is doesn't contain any 'random()' type functions.

Depending on what language you are calling from you could pass in a random number as a parameter and use something like:

match="banner[position()=($param mod last())]"


/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old October 17th, 2007, 10:02 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's no random number function in XSLT, though there is one in the EXSLT library (www.exslt.org) which may be available for your processor. If not, you'll have to implement your own extension function, or pass a random number in as a parameter. It depends a bit what you want to achieve - if the same transformation is done twice, do you want the same random number or a different random number?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old October 17th, 2007, 10:18 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to carlosaml
Default

Quote:
quote:Originally posted by mhkay
 There's no random number function in XSLT, though there is one in the EXSLT library (www.exslt.org) which may be available for your processor. If not, you'll have to implement your own extension function, or pass a random number in as a parameter. It depends a bit what you want to achieve - if the same transformation is done twice, do you want the same random number or a different random number?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To Select a specific nodes from XML vkommera XSLT 4 June 27th, 2008 03:39 PM
Session Variables Randomly Disappeared Dmitriy .NET Framework 1.x 1 November 30th, 2006 01:24 AM
How to select these nodes? hustsay23 XSLT 1 September 7th, 2006 04:15 AM
Help: Select every node except these nodes arcuza XSLT 8 May 25th, 2005 08:07 AM
Randomly choose Operator from Array interrupt Javascript How-To 2 April 9th, 2005 07:49 AM



All times are GMT -4. The time now is 07:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.