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

recursive addition

Subject: recursive addition
From: annirack@xxxxxxx
Date: Wed, 14 Jan 2004 12:40:36 -0800
recursive addition
I have a structure (much like a file system) where elements of the same type are linked together via IDs rather than the XML structure--i.e. all directory elements are at the same level.

For an arbitrary directory level element, I want to sum a numeric attribute for all linked elements and so on down the tree.

Is there any way to do this?  I know that recursion is the first step, but what I don't know how to sum an arbitrary number of parallel level attributes in different elements.

Here's an example:
<root>
   <folder files="2" id="dir0">
      <file id="dir1" />

      <file id="dir4" />
   </folder>

   <folder files="4" id="dir1">
      <file id="dir2" />

      <file id="dir3" />
   </folder>

   <folder files="3" id="dir2" />

   <folder files="6" id="dir3" />

   <folder files="7" id="dir4" />

   <folder files="5" id="dir5" />
</root>

If my arbitrary element id is "dir1", then the result should be 9. (folder[@id='dir2']/@files + folder[@id='dir3']/@files)

How do I do that with xsl?


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.