xsl-list
[Top] [All Lists]

Merging nested/adjacent nodes

2005-05-19 13:42:56
Hello,
I'm really stuck on this one.  It's probably a little too offbeat for
someone to just have the code handy ready to copy & paste.... but I
I'll give it a shot as I've already spent way too much time spinning
my wheels on it ;)

I basically want to merge adjacent nodes on a given attribute.  It
originally seemed would be simple enough to do with using
for-each-group and group-adjacent.  But the fact that I have mixed
nodes in there seems to screw that whole thing up.

---------------------------------------------------------------
Here's an example of a source doc.....
---------------------------------------------------------------
<employees>
        <supervisor name="jimmy">
                <supervisor name="bob">
                        <employee name="grunt_1"/>
                </supervisor>
        </supervisor>
        <supervisor name="jimmy">
                <supervisor name="bob">
                        <employee name="grunt_2"/>
                </supervisor>
        </supervisor>
        <supervisor name="jimmy">
                <employee name="grunt_3"/>
        </supervisor>
        <employee name="grunt_4"/>
        <supervisor name="jimmy">
                <supervisor name="bob">
                        <employee name="grunt_5"/>
                </supervisor>
        </supervisor>
</employees>

---------------------------------------------------------------
.... and here's what I would want to transform the source doc into.....
---------------------------------------------------------------

<employees>
        <supervisor name="jimmy">
                <supervisor name="bob">
                        <employee name="grunt_1"/>
                        <employee name="grunt_2"/>
                </supervisor>
                <employee name="grunt_3"/>
        </supervisor>
        <employee name="grunt_4"/>
        <supervisor name="jimmy">
                <supervisor name="bob">
                        <employee name="grunt_5"/>
                </supervisor>
        </supervisor>
</employees>
---------------------------------------------------------------

The order must be maintained and notice that the last 'supervisor'
node is not merged with the others of the same name because they're
not adjacent.
I'm using XSLT 2.0.  Any pointers would be MUCH appreciated.  

Thanks!

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>