Re: How to do this without updating a variable?
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.
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format