Subject: Re: [xsl] position behavior in nested grouping From: Ganesh Babu N <nbabuganesh@xxxxxxxxx> Date: Fri, 31 Jul 2009 09:48:28 +0530 |
Thanks Martin, It is working like a charm. Regards, Ganesh On Thu, Jul 30, 2009 at 7:12 PM, Martin Honnen<Martin.Honnen@xxxxxx> wrote: > Ganesh Babu N wrote: >> >> all those should be clubbed into single section by taking group-adjcent. >> >> The output should be >> >> <sections> >> <section-title>Contents</section-title> >> <section> >> <section-head>Abstracts of the Series >> of Fascia Congress - Part >> 4</section-head> >> <para> >> <page>270</page> >> </para> >> </section> >> <section> >> <section-head/> >> <para> >> <page>271</page> >> </para> >> <para> >> <page>271</page> >> </para> >> </section> >> <section> >> <section-head>Abstracts of the Series >> of Fascia Congress - Part >> 4</section-head> >> <para> >> <page>272</page> >> </para> >> </section> >> <section> >> <section-head>Prevention & >> Rehabilitation</section-head> >> <section-subhead>Editorial</section-subhead> >> <para> >> <page>273</page> >> </para> >> <para> >> <page>277</page> >> </para> >> </section> >> <section> >> <section-subhead>Learning >> Methodology</section-subhead> >> <para> >> <page>284</page> >> </para> >> </section> >> </sections> > > If you know that you want group-adjacent then it is only a slight change > from the earlier stylesheet: > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="2.0"> > > <xsl:output indent="yes"/> > > <xsl:template match="articles"> > <sections> > <section-title>Contents</section-title> > <xsl:for-each-group select="row" group-adjacent="if (col[2] = '') then > '' else tokenize(col[2], '\|')[1]"> > <xsl:choose> > <xsl:when test="contains(col[2], '|')"> > <xsl:variable name="outer-key" select="current-grouping-key()"/> > <xsl:for-each-group select="current-group()" > group-by="tokenize(col[2], '\|')[2]"> > <section> > <xsl:if test="position() eq 1"> > <section-head><xsl:value-of > select="$outer-key"/></section-head> > </xsl:if> > <section-subhead><xsl:value-of > select="current-grouping-key()"/></section-subhead> > <xsl:apply-templates select="current-group()"/> > </section> > </xsl:for-each-group> > </xsl:when> > <xsl:otherwise> > <section> > <section-head><xsl:value-of > select="current-grouping-key()"/></section-head> > <xsl:apply-templates select="current-group()"/> > </section> > </xsl:otherwise> > </xsl:choose> > </xsl:for-each-group> > </sections> > </xsl:template> > > <xsl:template match="row"> > <para> > <page><xsl:value-of select="col[3]"/></page> > </para> > </xsl:template> > </xsl:stylesheet> > > The problem why the previous solution skips the row elements with an empty > col[2] child element is that the tokenize function returns an empty sequence > for the empty string and that does not result in a group. But > group-adjacent="if (col[2] = '') then '' else tokenize(col[2], '\|')[1]" > avoids that problem and simply form a group for those elements with an empty > col[2]. > > -- > > Martin Honnen > http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] position behavior in nest, Martin Honnen | Thread | [xsl] Applying an XSLT-file to spec, Mark Aussems |
[xsl] Simple grouping with XSL2, Andy Kohn | Date | Re: [xsl] Simple grouping with XSL2, G. Ken Holman |
Month |