xsl-list
[Top] [All Lists]

RE: Continuously add to a parameter at each call

2005-11-10 08:21:24
Michael,

That was a great solution, worked like a magic after a few minor
modifications and the processing time has been reduced soooooo much

Thanks again for your help



-----Original Message-----
From: Haarman, Michael [mailto:mhaarman(_at_)ibsys(_dot_)com] 
Sent: Wednesday, November 09, 2005 6:14 PM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: RE: [xsl] Continuously add to a parameter at each call

Emil,

<Tasks>
<Task><Name>Hardware</Name><OutlineLevel>1</OutlineLevel><WBS>
1</WBS></T
ask>
<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></T
ask>
<Task><Name>Development</Name><WBS>2.1</WBS><Cost>1</Cost></Task>
<Task><Name>Test</Name><WBS>2.2</WBS><Cost>3</Cost></Task>
</Task>

For a document like the snip above, something like the following gets
very
close to what you want.  Things to note:

a) the top-level xsl:key instruction is standard means of grouping,
b) the *use* attr of key takes a XPath expression evaluating to a string
c) sum takes a node-set, which is the return type of key() function


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

  <xsl:key name="tasks" match="*/Task" use="substring(WBS, 1, 1)"/>

  <xsl:template match="/">
    <totals>
      <xsl:for-each select="*/Task[OutlineLevel = '1']">
        <p>
          <xsl:value-of select="Name"/> total: 
          <xsl:value-of select="sum(key('tasks', WBS)/Cost)"/>
        </p>
      </xsl:for-each>
    </totals>
  </xsl:template>

</xsl:stylesheet>


A plain English paraphrase of the select expression of the for-each is
obvious.  The select expression that does the work means:

From key table named 'tasks' select all nodes whose index equals the
value
of the WBS element of the context node (that is, Task nodes the value of
whose child OutlineLevel element equals '1'), and sum the values of all
Cost
children of those nodes.


HTH,

Mike

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--