Jeni's site also has some material on multi-level grouping.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: jozef(_dot_)aerts(_at_)xml4pharma(_dot_)com
[mailto:jozef(_dot_)aerts(_at_)xml4pharma(_dot_)com]
Sent: 24 September 2004 20:40
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: RE: [xsl] flat structure to deep structure in a smart way
Dear Michael,
Many thanks for the link. The article is a real eye-opener.
So I started:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:key name="A-key" match="line" use="item[(_at_)itemcount=1]"/>
<xsl:key name="B-key" match="line" use="item[(_at_)itemcount=2]"/>
<xsl:key name="C-key" match="line" use="item[(_at_)itemcount=3]"/>
<xsl:template match="root">
<xsl:element name="result">
<xsl:for-each select="line[count(. | key('A-key',
item[(_at_)itemcount=1])[1]) = 1]">
<xsl:element name="A">
<xsl:attribute name="Value"><xsl:value-of
select="item[(_at_)itemcount=1]" /></xsl:attribute>
<xsl:for-each select="key('A-key', item[(_at_)itemcount=1])">
<!-- we need to group the B-elements
How do we do that here ? -->
<xsl:element name="B">
<xsl:attribute name="Value"><xsl:value-of
select="item[(_at_)itemcount=2]"/></xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
which brings me:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<A Value="A1">
<B Value="B1"/>
<B Value="B22"/>
</A>
<A Value="A3">
<B Value="B3"/>
<B Value="B3"/>
<B Value="B3"/>
</A>
</result>
Now I got a bit stuck. Under the A3 I need to group the B-elements
again. How do I do that ?
I presume I need to change/add something to the
<xsl:for-each select="key('A-key', item[(_at_)itemcount=1])"> line
but it is not entirely clear how to do that.
P.S. Once this is solved I will post the full stylesheet as I
think this
a very typical problem from a sorted database table.
Many thanks in advance
Jozef
Michael Kay <mike(_at_)saxonica(_dot_)com> schrieb am 24.09.2004, 19:22:44:
In the element you see an A1 again, so B22
should fall
under A1 that's under line 1. I.e. if an element has the
same value as
in the previous line, it should become a subelement of
the first line.
What is the best strategy to accomplish this ?
As mentioned several times in the last couple of days, read
http://www.jenitennison.com/xslt/grouping
Michael Kay
http://www.saxonica.com/
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
--+--
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--