xsl-list
[Top] [All Lists]

## RE: group-by deep equality?

2006-01-10 14:34:25
```Actually 1 and 3 in your example aren't deep-equal() because the attribute
value is different. But if they were, I don't think that would make things
much easier.

I think the way to tackle this is to write a function that constructs the
grouping key you want as a string (perhaps using saxon:serialize()) and then
use for-each-group on that.

Michael Kay
http://www.saxonica.com/

```
```-----Original Message-----
From: David Sewell [mailto:dsewell(_at_)virginia(_dot_)edu]
Sent: 10 January 2006 21:14
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] group-by deep equality?

I'm trying to figure out how to group elements by deep
equality of node
sequences. Given input data like this:

<list>
<item n="1">Life of Brian</item>
<item n="2"><i>Life</i> of Brian</item>
<item n="3">Life of Brian</item>
<item n="4"><i>Life of Brian</i></item>
</list>

I want groups of <item> elements whose contents that are all
deep-equal() to one
another. So in this case there should be three groups:

<item n="1">Life of Brian</item>
<item n="3">Life of Brian</item>

<item n="2"><i>Life</i> of Brian</item>

<item n="4"><i>Life of Brian</i></item>

<xsl:for-each-group select="item" group-by="."> creates only
one group,
because the atomic value of each <item> node is the concatenated value
of descendant text nodes, i.e. "Life of Brian" in each case.

For the above data, the following will in fact produce the
desired three groups:

<xsl:for-each-group select="item" group-by="concat(.,
count(.//node()))">

but it's not a generalizable solution because it would treat

<item n="5">Life of <i>Brian</i></item>

as equivalent to item #2 (they both have 3 descendant nodes).

Is there a pure @group-by solution, or will this require
something more
complicated involving @group-by-adjacent and deep-equal()?

--
David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell(_at_)virginia(_dot_)edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/

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

```
```

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

```
 Current Thread group-by deep equality?, David Sewell RE: group-by deep equality?, Michael Kay <=