[xsl] transforming from flat to hierarchical "grouping"

Subject: [xsl] transforming from flat to hierarchical "grouping"
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx (by way of Mulberry Technologies List Owner)
Date: Wed, 18 Apr 2001 08:42:10 -0400
Subject: help: transforming from flat to hierarchical "grouping"
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 17 Apr 2001 21:29:39 -0400
Message-ID: <OFA0E7C551.C9E2D17E-ON85256A32.00048401@xxxxxxxxxxxxxx>
X-MIMETrack: Serialize by Router on Pan/PercWeb(Release 5.0.5 |September 22, 2000) at 04/17/2001
 09:31:52 PM
MIME-Version: 1.0
Content-type: text/plain; charset=us-ascii

I want to transform this source XML (fragment):

<article category="news">foo1</article>
<article category="news">foo2</article>
<article category="sports">foo3</article>
<article category="news">foo4</article>
<article category="sports">foo5</article>
<article category="local">foo6</article>

to this ouput XML:


Nowhere are the possible values of the "category" attribute defined.  Each
source XML is allowed to use any number of category values (and have any
number of articles) but each article has only one category attribute value.

I can get pretty close with this XSL:

  <xsl:template match="/">
      <xsl:apply-templates select="descendant::article"/>

  <xsl:template match="article">
    <xsl:element name="{@category}">
        <xsl:apply-templates />

But the output I get now is not "grouped" properly. It is:


The sorting does not matter, just that there can only be one <news>
element, one <sports> element, and so on for each category.

I'm using XT.

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

Current Thread