Re: [xsl] Continuously add to a parameter at each call

Subject: Re: [xsl] Continuously add to a parameter at each call
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Wed, 9 Nov 2005 15:52:20 -0600
On 11/9/05, Emil Soosaithasan <emils@xxxxxxxxxxxxxxxx> wrote:
> Jon
>
> Sorry for not including the cost per each task but your guess is right
> on the money.  I like the idea of grouping rather than going through
> many iterative loops but I am new to the XSL world and have no
> experience in grouping.  I will try to look at the faq on grouping but
> if you have some time, please give me a small sample code on how to
> group the tasks.

Well, a query took longer to run then I thought and I have a meeting a
few minutes so I don't have time to start anything else.  I'll give a
small example and try to explain my thinking.  This example is a
rather crudy one though, and there are better generic examples out
there.

Assuming this is our structure:



<Tasks>
<Task><Name>Hardware</Name><OutlineLevel>1</OutlineLevel><WBS>1</WBS></Task>
<Task><Name>Bringup</Name><WBS>1.1</WBS><Cost>12</Cost></Task>
<Task><Name>Testing</Name><WBS>1.2</WBS><Cost>22</Cost></Task>
<Task><Name>Software</Name><OutlineLevel>1</OutlineLevel><WBS>2</WBS></Task>
<Task><Name>Development</Name><WBS>2.1</WBS><Cost>1</Cost></Task>
<Task><Name>Test</Name><WBS>2.2</WBS><Cost>3</Cost></Task>
</Tasks>


First, when you see anything that is similar to "For  0 to n in
S[0...n] do y if x is true", you know you can just ask for the nodes
that fufill that condition.  In our case, we want to sum up the work
value for all  those tasks that are "under" a task with the broader
OutlineLevel.  Then we want to sum all those that belong to the same
hierarchy, indicated by the digit before the period.

  <xsl:template match="Tasks">

    <xsl:for-each select="Task[OutlineLevel]">
   <!-- I now have a node set consisting of the Task elements that had
a child OutlineLevel Element-->
      <xsl:value-of select="Name" /><xsl:text>
</xsl:text>

<!-- give me the sum of all the following Task elements that start
with the same WBS pattern.  You'll notice this is a bit crude, since
literally it looks at all the following task elements, but
optimization can be done later with better understanding-->

<xsl:variable name="level" select="WBS" />
<xsl:value-of select="sum(following-sibling::Task[substring-before(WBS,'.')
= $level]/Cost)" />
<xsl:text>
</xsl:text>
    </xsl:for-each>

  </xsl:template>





Jon Gorman

Current Thread