[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Muenchian grouping: help with 'use' and multiple elements


Subject: Re: [xsl] Muenchian grouping: help with 'use' and multiple elements
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 9 Jul 2004 22:28:21 +0100

Hi Justin,

> I'm trying to do single-level Muenchian grouping of r_ele elements
> by their re_restr children, of which there can be 0 to infinity
> instances in any order. I'm not sure if Muenchian grouping works
> when the 'use' element doesn't exist all the time, and I have no
> clue how to make the 'use' element consider all of the re_restr
> children in an r_ele at the same time.

I can't see a way to do this via Muenchian grouping in XSLT 1.0. You
need to be able to create the grouping key value by iterating over the
<re_restr> elements and combining their values into a string, as in:

  <xsl:for-each select="re_restr">
    <xsl:value-of select="." />
    <!-- use separator of your choice -->
    <xsl:text>,</xsl:text>
  </xsl:for-each>

It isn't possible to create this string with a single XPath 1.0
expression. So if you're using XSLT 1.0, your options are:

A. Use a two-pass transformation in which the first pass adds a 'key'
attribute to each <r_ele> element, containing the grouping key value,
and the second pass does the grouping based on that value. You'll need
to use a node-set() extension function to do this.

B. Create a user-defined function that can create the grouping key
value for a given <r_ele> element. You'll need to use an extension
element (e.g. <func:function> or <msxml:script>) to create the
user-defined function.

C. Do the grouping without using a key. This is likely to be
time-consuming (both for you writing it and for the processor running
it).

Of course, in XSLT 2.0 you can use the string-join() function:

  <xsl:for-each-group select="r_ele"
                      group-by="string-join(re_restr, ',')">
    ...
  </xsl:for-each-group>

Cheers,

Jeni

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


Current Thread
Keywords