Re: [xsl] xsl:for or xsl:repeat

Subject: Re: [xsl] xsl:for or xsl:repeat
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 24 May 2006 19:49:19 -0700
 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)

Usually a much bigger number can be obtained by:



document('')//node() | document('')//namespace::* | document('')//@*



because any namespace node is propagated down to all descendants of the element in which it initially was specified.


So the total number of namespace nodes is roughly O(N^2), where N is the average depth of the stylesheet's xml tree.


Cheers, Dimitre Novatchev


On 5/24/06, David Carlisle <davidc@xxxxxxxxx> wrote:

> 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
________________________________________________________________________




--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.

Current Thread