[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Continuously add to a parameter at each call

Subject: Re: Continuously add to a parameter at each call
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Wed, 9 Nov 2005 14:34:38 -0600
add total in xsl
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.