RE: [xsl] grouping children of same name parents under one common tag

Subject: RE: [xsl] grouping children of same name parents under one common tag
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Thu, 19 Jun 2003 14:47:44 -0500
This is a grouping problem.
will have some helpful pointers.

> Again, I don't know the tag names ahead of time(Bob, Sue, and 
> Warren are
> just examples).  I'm not sure how to tell xsl that I want to:
> 1) compare the current node's name with its siblings' names.

"local-name(.) = local-name(follow-sibling::*[1])", for example.
But what you probably want is a key on "local-name(.)".

> 2) if a name match is found, adopt the matched sibling's 
> children. (matched
> sibling can die now, how nice of me ;)
> 3) keep looking for more siblings with matching names, adopting their
> children if more matches are found.

You won't be modifying the source tree, so don't think of it in
terms of one node adopting another's children and another dying.

Rather, you will be outputting one node with the same name
as a set of input nodes (you could do this by using xsl:copy
on the first input node with a particular name) and then
copying all the children of the input node set as children
of your output node (using xsl:copy-of).

> 4) don't repeat steps 1-3 for matched siblings (not an issue 
> if they were
> killed in step 2 when their children were taken away).

This is where standard grouping techniques come in -- how to
eliminate the duplicates.  See the links above.

> Thanks for any help.  I'm having trouble accomplishing this, 
> even tho I
> know exactly what I want.

Indeed, you stated the problem like you know what you're talking
about.  It's just a matter of learning how this is done in XSLT.


 XSL-List info and archive:

Current Thread