Re: [xsl] find the maximum node count and loop with the count

Subject: Re: [xsl] find the maximum node count and loop with the count
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 18 Jun 2001 00:22:38 -0700 (PDT)
Jayaranga Subasinghe wrote:

> hi,
> can anybody give me the soluton for that?
> i want to find the maximum node count and print a text line equals to that
>maximum node count.

Hi Jayaranga,
It is a little bit difficult to understand what maximum node count (of what?) you
need and for what purposes.

I'm assuming here that you need a large repository of "raw nodes" upon which to
build a non-recursive loop (the method of Wendell Piez).

The answer is that you may include in your stylesheet very large xml documents and
achieve as big a count as you may need.

For more information see:

Any stuff can be included under a namespace-uri, different from 
the standard XSLT namespace-uri, like this:

<xsl:stylesheet version='1.0'

    <!-- Hamlet goes here -->

  <!-- the rest of the stylesheet -->

As it can be seen, I included Jon Bosak's xml version of "Hamlet"
The following small template will return the number of nodes
(the maximum recursion depth that can be avoided) we can now use 
to organise non-recursive loops:

<xsl:template match="/">
  <xsl:variable name="st" select="document('')"/>
  <xsl:value-of select=" count($st//node() | $st//@* | $st//namespace::*)"/>
For the above stylesheet this number is: 32032.
As some people noted, this solution could be called an ugly one.
Or, to quote an xml fragment from our stylesheet, 

  <LINE>Something is rotten in the state of Denmark. </LINE>

However, it is much more ugly to watch the slow and painful agony 
of IIS crashing only because we used a beautiful, deep recursive processing.

Hope this helped.

Dimitre Novatchev.

Do You Yahoo!?
Spot the hottest trends in music, movies, and more.

 XSL-List info and archive:

Current Thread