[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:for or xsl:repeat

Subject: Re: xsl:for or xsl:repeat
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 24 May 2006 23:54:41 +0100
xsl repeat
> Just a quick, somewhat stupid question that probably won't come up in
> any real practicality.  What if there is the need to iterate more than
> there are nodes in the document?

well for any fixed number you can ensure that the document you use for
the iteration (which doesn't have to be your source document) has
enough nodes: for example you can use the stylesheet
document('')//node()
and have as many nodes as you want in that (add 1000 empty comments at
the end if need be)
if you are picking up a number dynamically it's probably easier to just
give in and write the recursive template (which after all is only 4 or 5
lines of code) apart from anything else loading a massive document just
tp iterate overthe integers is a bit expensive.
But if you really want to use //node() then
z=document('')//node())
m=count($z)
a=floor($n div $m)
b=$n - $a*$m
for-each $z[position() <= $a]
  for-each $z
for-each $z[position() <= $b]

will do any number of iterations up to the square of the number of nodes
in the stylesheet which can be a pretty big number.
(I may have got the sums wrong but too late to think about that too
hard)

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.