Subject: RE: RE: [xsl] flat structure to deep structure in a smart way From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Fri, 24 Sep 2004 22:01:35 +0100 |
Jeni's site also has some material on multi-level grouping. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: jozef.aerts@xxxxxxxxxxxxxx [mailto:jozef.aerts@xxxxxxxxxxxxxx] > Sent: 24 September 2004 20:40 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 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[@itemcount=1]"/> > <xsl:key name="B-key" match="line" use="item[@itemcount=2]"/> > <xsl:key name="C-key" match="line" use="item[@itemcount=3]"/> > > <xsl:template match="root"> > <xsl:element name="result"> > <xsl:for-each select="line[count(. | key('A-key', > item[@itemcount=1])[1]) = 1]"> > <xsl:element name="A"> > <xsl:attribute name="Value"><xsl:value-of > select="item[@itemcount=1]" /></xsl:attribute> > <xsl:for-each select="key('A-key', item[@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[@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[@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@xxxxxxxxxxxx> 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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: RE: [xsl] flat structure to dee, jozef.aerts | Thread | Re: [xsl] flat structure to deep st, Jeni Tennison |
Re: [xsl] Specify/determine element, Wendell Piez | Date | Re: [xsl] flat structure to deep st, Jeni Tennison |
Month |