[xsl] Re: Problem with Muenchian grouping

Subject: [xsl] Re: Problem with Muenchian grouping
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 7 Nov 2003 19:25:32 +0100
> I'm a newbie at XSL, and I have a question regarding Muenchian grouping.
> I've read some threads about it, but can't figure out how to solve my
> problem.

[snip]

> I'm interested in the children of <data> that have an <action> child: I
> would like to group them by name and perform some processing on them.
> The problem is I cannot know those names (that is, each element is
> optional), and the number of elements of each category is undefined.
> So I don't know how to define the <xsl:key> element that I need.
> I have tried <xsl:key name="records-by-name" match="/*/*[action]"
> use="name()"> but that doesn't seem to work.

Why, it works:

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="text"/>

  <xsl:key name="kWithAction" match="data/*[action]"
   use="name()"/>

    <xsl:template match="/">
      <xsl:for-each
       select="/*/data/*[generate-id()
                        =
                         generate-id(key('kWithAction',
                                         name()
                                         )[1]
                                     )
                        ]">
        <xsl:value-of select="concat(name(), '&#xA;')"/>
      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

when applied on this xml.source:

<dump>
    <identification>
        ...
    </identification>
    <data>
        <project>
            ....
        </project>
        ...
        <projectmission>
            <action> delete</action>
             ....
        </projectmission>
        ...
        <breakdown>
            <action> update</action>
            ....
        </breakdown>
        <projectmission>
            <action> update</action>
             ....
        </projectmission>
        <breakdown>
            <action> add</action>
            ....
        </breakdown>
        <projectscope>
            <action> update</action>
             ....
        </projectscope>
        ....
    </data>

</dump>


produces the wanted result:

projectmission
breakdown
projectscope



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




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


Current Thread