RE: [xsl] transforming from flat to hierarchical "grouping"

Subject: RE: [xsl] transforming from flat to hierarchical "grouping"
From: "Jarno Elovirta" <jarno@xxxxxxxxxxxxxx>
Date: Wed, 18 Apr 2001 16:40:31 +0300
Hip hei!

> 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'm using XT.

How about

[c:\temp]type test.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>

[c:\temp]type test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"

<xsl:output method="xml"
            indent="yes" />

<xsl:template match="/">
  <!-- Select every article which is not preceded by an article with of same
category, i.e. the first of every category -->
  <xsl:apply-templates select="descendant::article[not(@category =
preceding::article/@category)]" />

<xsl:template match="article">
  <xsl:element name="{@category}">
    <!-- Process the current article, which is the first of that category
and all following ones, too -->
    <xsl:for-each select=". | following::article[@category =
        <xsl:apply-templates />


[c:\temp]xt test.xml test.xsl
<?xml version="1.0" encoding="utf-8"?>

You should use preceding-sibling and following-sibling axis if you can,
faster that way. There are people on this list who will give you a better

Jarno - Assemblege 23: Love My Way (Psychadelic Furs cover)

 XSL-List info and archive:

Current Thread