Re: [xsl] How to do this without updating a variable?

Subject: Re: [xsl] How to do this without updating a variable?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Sep 2005 19:00:46 -0400

At 06:20 PM 9/7/2005, Jay wrote:
Here's one way:
            <td><xsl:value-of select="."/></td><td><xsl:value-of
select="sum(preceding::reg/@count) + 1"/></td><td><xsl:value-of
select="sum(preceding::reg/@count) + @count"/></td>

Note that Jay's solution works completely differently from your stated expectation. He is simply traversing the preceding:: axis to collect all reg/@counts appearing before the current one, in order to calculate what its start and end values should be.

That is, where you suggest

So basically output of any node <reg> is based on all the <reg> nodes that
have been processed before it.

Jay silently amends this to read "[the] output of any node <reg> is based on all the <reg> nodes that *appear* before it".

Notice that this restates the problem in a way that has no dependency on processing order, but instead refers simply and solely to the organization of the input.

This is the XSLT way of doing things. Focus on what has to be done and let the processor figure out how to do it.

This can take some getting used to if you are accustomed to managing the flow of control yourself (as you must with procedural languages). But it allows many advantages (including allowing processors to optimize for speed and efficiency in various ways). And once you're used to thinking this way, you may even find it easier (some of us think much easier), because the processor does so much of the work for you.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 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 ======================================================================

Current Thread