xsl-list
[Top] [All Lists]

Re: grouping probs

2002-09-16 08:43:17
Hello Laura,

I do not know what the attribute would be called like in my example
, for one set , its called 'type', and for the other set, its called
'catagory'.. so what i want to do is..

go through each element, and if it has the same attribute value and
same set of children..( children with same attribute value and same
set of their children), then eliminate the duplicate.

Hmm... I think that the kind of generic grouping solution for every
possible grouping problem that you describe is likely to be complex,
inefficient and hard to maintain. You would need to create a
stylesheet that checked every previous instance of elements with the
same name and did a deep comparison of their children and attributes.

I think that overall you will find it easier to write, use and
understand code written specifically for the particular duplication
problems that you need to solve. Once you get used to the Muenchian
pattern, I honestly don't think it's that hard to do.

If for some reason you have to create something this general purpose
(for example, if you're writing a stylesheet for displaying any XML
document that it's passed), what I suggest is that you use a two-pass
method, where the first pass over your data (or preferably a schema)
creates a stylesheet that can make a second pass over your data that
will remove the duplicates.

Alternatively, if you're looking for a generic solution because
writing the code for the individual solutions is too tedious, I
suggest that you either use extension/XSLT 2.0 grouping elements (e.g.
saxon:group/xsl2:for-each-group), or that you use a literate
programming approach, where you write a "stylesheet" that contains
elements (which you make up yourself) that describe the duplicate
removal that you want to do, and then write another stylesheet that
transforms that stylesheet into proper XSLT.

I'm sure that we'll all be happy to assist with any of these paths,
but I wanted you to be aware of the range of possible routes you could
take to achieve the duplicate removal that you're after. If you're not
sure which to choose, perhaps you can describe the problem that you're
actually trying to solve and we can advise you on that basis.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



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