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

Subject: RE: [xsl] Continuously add to a parameter at each call
From: "Emil Soosaithasan" <emils@xxxxxxxxxxxxxxxx>
Date: Wed, 9 Nov 2005 15:51:34 -0500
In MS Project, all tasks whether low-level or top-level are grouped as
tasks, for example:

<Tasks>
<Task><Name>Hardware</Name><OutlineLevel>1</OutlineLevel><WBS>1</WBS></T
ask>
<Task><Name>Bringup</Name><WBS>1.1</WBS></Task>
<Task><Name>Testing</Name><WBS>1.2</WBS></Task>
<Task><Name>Software</Name><OutlineLevel>1</OutlineLevel><WBS>2</WBS></T
ask>
<Task><Name>Development</Name><WBS>2.1</WBS></Task>
<Task><Name>Test</Name><WBS>2.2</WBS></Task>
</Task>

The way I group these is by <WBS>, if you notice carefully - "Hardware"
has a <WBS> of "1" which means it's a Top-Level task.  "Bringup" is a
low-level task that falls under "Hardware" because it has a <WBS> of
"1.1".  "Testing" is also another low level task under "Hardware".
Similar arguments can be made for the Top-Level task "Software" and its
tasks.

The following is the algorithm I use:

<For each (Task)>	//Search through all tasks
	<If (OutlineLevel = 1)>
		<Get WBS_high>

	<For each (Task)>	//Search through all the tasks for the
second time
		<Get WBS_low>

		<If WBS_high = WBS_low>
			<Get Cost>

Inside this loop is where I can get the cost of the task but can't
figure out how to have a running total for each of the high-level
task!!!


-----Original Message-----
From: Jon Gorman [mailto:jonathan.gorman@xxxxxxxxx]
Sent: Wednesday, November 09, 2005 3:35 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Continuously add to a parameter at each call

On 11/9/05, Emil Soosaithasan <emils@xxxxxxxxxxxxxxxx> wrote:
>
> To elaborate on my problem, For each of the Top Level Tasks - I have
to
> search through each Assignment - obtain the task that is related to
the
> assignment - check if the task obtained falls under the top-level task
-
> and if it does then get the cost.

Why do you have to do this?  Perhaps I'm missing something, but it's
not clear why you can't just follow Michael's advice and do this in a
more declartive way.

Lets say you have the following XML (I have no idea what MSProject looks
like)

<doc>

<hardware>

<task type="a">12</task>
<task type="b">12</task>
<task type="a">22</task>

</hardware>

<software>
<task type="a">2</task>
<task type="b">42</task>
<task type="a">5</task>
</software>

<analysis>
<task type="a">1</task>
<task type="b">3</task>
<task type="a">2</task>

</analysis>

</doc>

The following xslt script will give you totals for the value in each
catagory and the grand total.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

version="1.0">

  <xsl:output method="text" />

  <xsl:param name="type" select="'a'" />

  <xsl:template match="/doc">
    Value of hardware: <xsl:value-of
select="sum(hardware/task[@type=$type])" />
    Value of software: <xsl:value-of
select="sum(software/task[@type=$type])" />   Value of analysis:
<xsl:value-of select="sum(analysis/task[@type=$type])" />
  Grand Total: <xsl:value-of select="sum(*/task[@type=$type])" />
  </xsl:template>


</xsl:stylesheet>


If you really need to do this in a more procedural way, use some
recursion, have a template that takes two parameters, a node set and a
value.  Call the same template with the node set of all the other
nodes (position > 1) and the value increased by the amount in the
first node.  Do this until no nodes are in the list and print the
list.

Jon Gorman

Current Thread