[XSL-LIST Mailing List Archive Home]
RE: [xsl] Efficient recursive grouping in XSLT 1.0?
Subject: RE: [xsl] Efficient recursive grouping in XSLT 1.0?|
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Sat, 20 Mar 2004 13:28:52 +0100
> -----Original Message-----
> From: Ian Young
> # Just out of curiosity: have you thought about doing the transformation
> # in one step using multiple keys to achieve the grouping?
> # Some keys like:
> # <xsl:key name="by-depth-and-name" match="*"
> # use="concat(count(ancestor::*),' ',name())" />
> # <xsl:key name="by-depth-parent-and-name" match="*"
> # use="concat(count(ancestor::*),' ',name(parent::*),' ',name())/>
> Interesting. Though I'm not sure I've quite understood how this is
> supposed to work. The keys are grouped only on depth, element name and
Well, as I posted my solution, the thought struck me that the first key
seems superfluous. Probably has something to do with solving parts of the
problem, and glueing the parts back together again later...
The first key groups on depth and name, so where I say:
<xsl:variable name="vsame" select="key('by-depth-and-name',concat(
I could just as easily write:
<xsl:variable name="vsame" select="key('by-depth-parent-and-name',
concat($vdepth,' ',$vparent,' ',name()))" />
My general impression was that you needed to be able to approach all
identically named nodes at the same depth, having an identically named
parent. So the latter key should be sufficient to group the nodes as
> would yield:
> <root ct="1">
> <a1 ct="1">
> <a2 ct="1">
> <a3 ct="2"/>
> <b1 ct="1">
> <a2 ct="1"/>
No, because the value for the ct attribute for the first a3 node (descendant
of a1-a2) is
and this variable (see above) contains only the a3 nodes that are at the
same depth and have a parent that has the same name (a2). Since there are no
other such nodes, the count will be 1 as desired. And in the b1 node, an a3
node will be added which has no corresponding nodes at that depth (named a3
and having a parent b1), so the ct attribute will also be set to 1.
Hope this clears it up a bit...
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list