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[(_at_)id='dir2']/@files + folder[(_at_)id='dir3']/@files)
How do I do that with xsl?
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list