|
Subject: Re: [xsl] position behavior in nested grouping From: Ganesh Babu N <nbabuganesh@xxxxxxxxx> Date: Thu, 30 Jul 2009 18:09:46 +0530 |
Hai,
the code is working fine for this input. But If you have empty col[2].
It is not working. Please refer new input below:
Old Input
======
<articles>
<row>
<col>627</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>270</col>
</row>
<row>
<col>661</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>270</col>
</row>
<row>
<col>676</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>271</col>
</row>
<row>
<col>719</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>272</col>
</row>
<row>
<col>706</col>
<col>Prevention & Rehabilitation|Editorial</col>
<col>276</col>
</row>
<row>
<col>690</col>
<col>Prevention & Rehabilitation|Editorial</col>
<col>283</col>
</row>
<row>
<col>721</col>
<col>Prevention & Rehabilitation|Learning Methodology</col>
<col>291</col>
</row>
</articles>
New Input:
<articles>
<row>
<col>627</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>270</col>
</row>
<row>
<col>661</col>
<col/>
<col>270</col>
</row>
<row>
<col>676</col>
<col/>
<col>271</col>
</row>
<row>
<col>719</col>
<col>Abstracts of the Series of Fascia Congress - Part 4</col>
<col>272</col>
</row>
<row>
<col>706</col>
<col>Prevention & Rehabilitation|Editorial</col>
<col>276</col>
</row>
<row>
<col>690</col>
<col>Prevention & Rehabilitation|Editorial</col>
<col>283</col>
</row>
<row>
<col>721</col>
<col>Prevention & Rehabilitation|Learning Methodology</col>
<col>291</col>
</row>
</articles>
I am unable to provide two values in group-by attribute. Please
suggest how to achieve this.
Regards,
Ganesh
On Wed, Jul 15, 2009 at 6:20 PM, Martin Honnen<Martin.Honnen@xxxxxx> wrote:
> Ganesh Babu N wrote:
>
>> I need to find out the starting group or group[1] in the inner loop so
>> that i can append <section-head> to that.
>>
>> binding a variable in outer loop is giving the group position with
>> respect to outer loop. But I need the position with respect to inner
>> loop.
>
> I think you need to reorganize your grouping code to achieve the output you
> want. Try whether the following does what you want:
>
> <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-by="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>
>
> In your original stylesheet you end up with three groups in the outer
> grouping and then the inner grouping simply has only one group for each of
> the (last two) groups in the outer grouping.
>
>
> --
>
> Martin Honnen
> http://msmvps.com/blogs/martin_honnen/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] position behavior in nest, Martin Honnen | Thread | Re: [xsl] position behavior in nest, Martin Honnen |
| Re: [xsl] XSLT 2.1, James A. Robinson | Date | Re: [xsl] position behavior in nest, Martin Honnen |
| Month |