Re: [xsl] ordering and iteration problem

Subject: Re: [xsl] ordering and iteration problem
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 01 May 2001 16:32:35 +0100
Mark:

At 06:44 PM 5/1/01, you wrote:
I'm curious why one typically initializes "random-nodes" from the
stylesheet document rather than the input document.  It seems to me
that the input document is guaranteed to have enough nodes, while the
XSLT transform document might not if the input document is big enough.

Instead of

<xsl:variable name="random-nodes" select="document('')//node()" />

I tried

<xsl:variable name="random-nodes" select="//node()" />

to get the set of all nodes from the input document.  This seems to
work for me.  I was wondering if there is any reason why this is not
what is typically done.

No reason. One could speculate about how this technique tends to be a 'pull' technique, and that in 'pull' applications stylesheets tend to be largish (XSLT verboseness) but source documents, smallish, whereas the reverse might be the case in a 'push' application. But really, that'd be pushing it: maybe we're just showing off how we know how to use document('').


The only thing to be careful about is to make sure you have *enough* nodes, which is why this iteration workaround (which of course fails without any warning if your node set falls short) is kind of scuzzy compared to a proper solution using recursion.

But as long as you're going to do it, declaring a global variable like yours (I'm assuming you're declaring $random-nodes at the top level, since you don't want to call '//node()' every time you hit a template) is a fine way to go; using a $plenty-of-nodes variable that's already been declared for some other purpose is even better.

(Jeni, what's your perspective?)

Regards,
Wendell

======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread