[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: "Emil Soosaithasan" <emils@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Nov 2005 10:21:24 -0500
RE:  Continuously add to a parameter at each call
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@xxxxxxxxx]
Sent: Wednesday, November 09, 2005 6:14 PM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE:  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:

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.