At 05:00 AM 3/17/2004, Michael Müller-Hillebrand wrote:
I use this set of nodes just for the sake of looping a certain number of
times. In Jeni Tennison's book "XSLT and XPath On The Edge" it is called
"The Piez Method". You are right, I don't need two variables (just an old
habit...).
Will I ever live it down? But yes ... and Mike knows the provenance of the
technique. :->
Jeni called it that because she was tickled (she said) by how
counter-intuitively obvious it was as a way of avoiding more cumbersome
methods, and wanted to give me credit for its small measure of tricky (if
not diabolical) inventiveness (my words not hers: her word might have been
"sweet"). But everyone who uses it (including me, when I do) should really
be ashamed of themselves. At best, it's a shortcut and should be avoided
except in very constrained circumstances. Such as: you don't need to
iterate many times in any case, and a node set guaranteed to be large
enough is readily available. One rule of thumb: if you need to go parse
something to get enough nodes, it's not worth it. Another: don't ever look
at set X and suppose that you need to iterate count(X) times -- just
iterate over the set X that you would have counted. That is, it's silly to
do this:
<xsl:for-each select="$bignodeset[position() <= count($nodeset)">
...
</xsl:for-each>
when you could simply do
<xsl:for-each select="$nodeset">
...
</xsl:for-each>
Believe it or not, I've seen it done the hard way.
All in all, I can think of other ways I'd rather go down in history. If
only I'd first figured out positional grouping using keys!
Cheers,
Wendell
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
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