Subject: Re: [xsl] Continuously add to a parameter at each call From: Jon Gorman <jonathan.gorman@xxxxxxxxx> Date: Wed, 9 Nov 2005 14:34:38 -0600 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Continuously add to a par, Emil Soosaithasan | Thread | RE: [xsl] Continuously add to a par, Emil Soosaithasan |
Re: [xsl] Dynamic XPath Expression, George Cristian Bina | Date | RE: [xsl] Continuously add to a par, Emil Soosaithasan |
Month |