[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Efficient recursive grouping in XSLT 1.0?

Subject: RE: Efficient recursive grouping in XSLT 1.0?
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Sat, 20 Mar 2004 13:28:52 +0100
xsl key efficient
> -----Original Message-----
> From: Ian Young
>
  # ME:
> # 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

Hi,

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(
                               $vdepth,' ',name()))[
                                 parent::*[name()=$vparent]]" />

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
desired.

So,

<snip />
>
> would yield:
>
> <root ct="1">
>   <a1 ct="1">
>     <a2 ct="1">
>       <a3 ct="2"/>
>     </a2>
>   </a1>
>   <b1 ct="1">
>     <a2 ct="1"/>
>   </b1>
> </root>
>

No, because the value for the ct attribute for the first a3 node (descendant
of a1-a2) is

count($vsame)

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

Cheers,

Andreas


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.